I am using WPF XamDataGrid, 2012.1 in .NET 4.0. I need to change the text in the column headers of the grid based on at least one, sometimes 2 and 3 properties contained in a nested viewmodel. The datacontext of the main form is the view model, "MainViewModel". The datacontext of the data grid is "CurrentCase.Segments", where Segments is an Observable collection. The MainViewModel contains a public property called "CurrentCase", which is an instance of a "Case", which is a class containing the properties which determine how to display the data grid header labels. Segments is an ObservableCollection property contained in the Case class.
So, basically I need bind the label of the header as such:
Label="{Binding CurrentCase, Path=IsCircularPipeEnabled", Converter=headerConverter, ConverterParameter='{0} Diameter'}"
The converter and converter parameter combine to test the value of the bool IsCircularPipeEnabled and supply a value for the {0} placeholder used in String.Format.
I've looked at many examples and posts, but can't seem to find one that works.
Can you offer any example or suggestions on how to acheive this?
Hello,
I am just checking if you require any further assistance on the matter.
Thank you for your reply. I am attaching a sample(XamDataGridLabelBinding.zip) where I have bound the Label of the Field to property of the viewmodel.
Yanko,
While I appreciate your response, I feel this is not an acceptable solution.
I will have approximately 120 columns in my grid header. Of those 120 columns, approximately 110 will change their content based on run conditions.
Since the header content (label) is obviously bindable, why can it not bind to a property of the view model rather than to an element on the form? I've tried many scenarios to bind to a view model, with no success.
Does this neet to be a feature request? It seems so obvious.
This is a separate MS label control on the window. I am attaching the sample application(LabelPresenterBinding.zip).
Thanks for the reply.
In your example, what does label1 represent. Is it really the name of the columns label?