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.


Need Your Help

Transcription cipher encryption program crashes

c++

I don't know how to solve it. It does the job, everything looks good, but it crashes at the end of encrypting.

Load BitmapImage in background thread causes UI thread to stutter

c# wpf multithreading xaml

I have a bit of code which loads a BitmapImage in the background, freezes it, and sends it off to the UI thread. However, even without sending to the UI thread, the act of loading a JPG into a

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.