Connect value to header of gridviewcolumn?

Is it possible?

I have a listview with multiple gridviewcolumns. The last column has a dynamic header. I don't know what the column heading will be at design time. This is actually the number that I want to display as a string.

    <GridViewColumn Header="{Binding Path=SomeValue}" 
                    DisplayMemberBinding="{Binding Path=OtherValue}"/>

      

This does not work. The data will be bound fine, only the header is left blank. While executing the code, it doesn't even break the SomeValue property.

+1


source to share


2 answers


I think your problem is the source of the SomeValue property. If you are binding to a list of objects, it would be pointless to have a title defined by a property of that object, because then you could have a different title for each object. Basically, you are saying, "Bind the column header to the" SomeValue "property, which lives on the same object as the" OtherValue "property." SomeValue "must come from a source other than the list that the grid item is bound to. You either need to set the RelativeSource property or the" ElementName "property in the binding.



+2


source


2.Create datacontext spy class accourding to the post in step 1 (copy and paste it, that's a few lines)



3.usage datacontext spy

<common:DataContextSpy x:Key="dci" DataContext="{Binding SomeProperty}" />

<DataGridTemplateColumn Header="{Binding Source={StaticResource dci},  
                        Path=DataContext.SomePropertysListOfValues[14]}">

      

+1


source







All Articles