Databind a value to a gridviewcolumn header?

Is it possible?

I have a listview with several gridviewcolumns. The last column has a dynamic header. I dont know what the column header will be at design time. It's actually a number I want to display as a string.

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

This doesn't seem to work. The data will bind fine just the header remains blank. Stepping through the code and it doesn't even break on the SomeValue property.

Answers


I think your problem is the source of the "SomeValue" property. If you are binding to a list of objects, it wouldn't make sense to have the header determined by a property on that object, because then you could have a different header for every object. Essentially what you are saying is "Bind the header of the column to the 'SomeValue' property which lives on the same object that my 'OtherValue' property does." The "SomeValue" needs to come from a different source other than the list your grid item is bound to. You need to either set the "RelativeSource" or the "ElementName" property in the binding.


  1. read a post http://blogs.infragistics.com/blogs/josh_smith/archive/2008/06/26/data-binding-the-isvisible-property-of-contextualtabgroup.aspx

2.create a datacontext spy class accourding to the post in step 1 (copy and paste it, it's a couple of lines)

3.usage the datacontext spy

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

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

Need Your Help

get rid of .AppleDouble files in git status

git ubuntu virtualbox

I have a virtual-box with installed Ubuntu on it. All new projects I start working on have some weird .AppleDouble files. So every time I check my git status they are appear in the log, unless I in...

Compiler error C2064 in functional when try to initialise a std::thread in a class constructor

c++ multithreading c++11 stdthread

I am writing a class which uses a thread and I wanted to try the new C++11 std::thread. I am compiling with Microsoft Visual Studio Pro 2013 v12.0.31101.00 Update 4. The update is from Nov 2014 so...