How to bind from DataGridColumn.Header to ViewModel property?

One simple solution would be to use a named resource.

Up vote 0 down vote favorite share g+ share fb share tw.

I want to bind my datagrid header to a property on the DataContext of the grid. Now, I got it to work, but I consider this a temporarily solution: The biggest issue with this solution is that it makes the binding more fragile (context sensitive). If the DataContext of the grid is used in a master/detail scenario (which makes the DataContext a BindingList instead of a single item) I would have to replace update the DataGrid DataContext with DataContext={Binding /}.

Is there a more robust way to bind from the DataGrid. HeaderTemplate than using ElementName and refering to the DataContext? Wpf link|improve this question edited Sep 28 '10 at 19:11Robaticus8,6422822 asked Sep 28 '10 at 16:53Marius1,090511 85% accept rate.

One simple solution would be to use a named resource ... Header="{Binding Path=HeaderText, Source={StaticResource MyHeaderProvider}" If everything is really dynamic this may not work. When I made a grid with more dynamic/data driven columns I did not define them in XAML but generated them in the code behind, where you don't have to do relative DataContext.

The alternative I mentioned (creating the column definitions in the CS file, not XAML) might be better for you. – Alex Lo Sep 28 '10 at 20:14 here are two decent resources about doing dynamic column creation: elegantcode.com/2010/03/08/… AND silverlightshow.net/items/… – Alex Lo Sep 28 '10 at 20:26.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions