Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Best way to bind to a header of a column of a DataGrid

$
0
0

Hi,

directly binding by setting Header={Binding PropertyName} seems not be possible. So far I found several ways to bind to a header of a DataGrid. One can be found here. The prefered way until now I use is

<Grid.Resources><FrameworkElement x:Key="ProxyElement" DataContext="{Binding}" /></Grid.Resources><ContentControl Visibility="Collapsed" Content="{StaticResource ProxyElement}" /><DataGrid AutoGenerateColumns="False"><DataGrid.Columns><DataGridTemplateColumn Header="{Binding DataContext.NameText, Source={StaticResource ProxyElement}}"><DataGridTemplateColumn.CellTemplate><DataTemplate><!-- ... --></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid>

Are there other solutions? Is there a best way to bind to a header?


Viewing all articles
Browse latest Browse all 18858

Latest Images

Trending Articles



Latest Images