A simple solution to that problem is presented on the Developer Code Samples Gallery (Binding of DataGrid column header) and the TechNet Wiki (Binding of DataGrid Column Header).
There are several solutions for this problem. I will introduce the simplest solution (in my opinion). Since DataGridColumn does not inherit the DataContext of the superior element, you have to indicate the DataContext to use. This can be easily done as the following code snippet shows.
<
DataGrid
>
<
DataGrid.Columns
>
<
DataGridTemplateColumn
>
<
DataGridTemplateColumn
.Header
>
<
TextBlock
Text
=
"{Binding DataContext.HeaderNameText, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
/>
</
DataGridTemplateColumn
.Header
>
</
DataGridTemplateColumn
>
</
DataGrid
.Columns
>
<
DataGrid
>
As you can see the header is defined by using a TextBlock. The Text property of the TextBlock is bound to the property HeaderNameText of the DataContext of the DataGrid. In a similar way you could use your own DataContext for the DataGridColumns. By defining the header in this way you could further customize your header by using further elements, e.g. Images. The DataContext of the DataGrid is set in code.
Data data =
new
Data();
data.HeaderNameText =
"Header2"
;
data.Items =
new
List<
string
>() {
"Item1"
,
"Item2"
};
DataContext = data;
The DataContext is an own object containing the values of the DataGrid and the Header name.
public
class
Data
{
public
string
HeaderNameText
{
get
;
set
;
}
public
List<
string
> Items
{
get
;
set
;
}
}
This comment has been removed by the author.
ReplyDeleteI have tried the same but no success.. not working !!
DeleteYou can find an working example on the Developer Code Samples Gallery (http://code.msdn.microsoft.com/Binding-of-DataGrid-column-73f80f68). You can use the code as starting point. But you can post your code that is not working, so I have a look at it.
DeleteHow to header set dynamic
ReplyDeleteThe header is set dynamically by binding as you can see in the post. You can find an working example on the Developer Code Samples Gallery (http://code.msdn.microsoft.com/Binding-of-DataGrid-column-73f80f68).
Delete649C9
ReplyDeleteSonm Coin Hangi Borsada
Görüntülü Sohbet Parasız
Coin Kazma Siteleri
Hexa Coin Hangi Borsada
Tumblr Beğeni Satın Al
Dlive Takipçi Hilesi
Görüntülü Sohbet
Referans Kimliği Nedir
Threads Beğeni Satın Al
22A2C
ReplyDeleteOnlyfans Beğeni Satın Al
Anc Coin Hangi Borsada
Onlyfans Beğeni Hilesi
Binance'de Kaldıraç Var mı
Bitcoin Madenciliği Nedir
Ceek Coin Hangi Borsada
Linkedin Beğeni Satın Al
Bitcoin Kazanma
Referans Kimliği Nedir
7BC80
ReplyDeletepancakeswap
onekey
uniswap
metamask
aave
dextools
roninchain
trust wallet
arbitrum
66F4F
ReplyDeletepancakeswap
thorchain
phantom wallet
dao maker
pancakeswap
dexscreener
pinksale
poocoin
layerzero
GHFBFTGN
ReplyDeleteشركة عزل اسطح بجازان
شركة تسليك مجاري بالدمام aSTaumHs5b
ReplyDeleteرقم المجاري بالاحساء h2hRd95bOb
ReplyDeleteشركة رش مبيدات بالاحساء ue0JpzBKga
ReplyDelete