views:

21

answers:

2

What might cause the value of a Silverlight 4 DataGridTextColumn.Header to display as System.Windows.Data.Binding rather than the resolved bound value? It seems like a ToString is happening somewhere that displays a class name rather than the formatted value of the class.

The binding looks like this

Header="{Binding Path=Dummy,Source={StaticResource languagingSource},Converter={StaticResource languagingConverter},ConverterParameter=vehicleDescription}"

and the problem doesn't lie anywhere within the binding as identical bindings, with different ConverterParameter values, work fine for Button.Content and TextBlock.Text properties within the same XAML page.

Even creating a simple string property like this within the local data context has the same result.

public string DataGridHeaderDescription { get { return "Description"; } }

Header="{Binding DataGridHeaderDescription}"

I've even tried adding a string format

Header="{Binding DataGridHeaderDescription,StringFormat=\{0\}}"

but this has no effect either.

A: 

After some further searching I found this thread that answers the question and gives some suggested solutions.

Dynamically setting the Header text of a Silverlight DataGrid Column

Steve Crane
+1  A: 

It is now possible to using bindings even on elements that aren't derived from FrameworkElement however the property of the element being bound must be defined as a DependencyProperty which Header is not.

Since Header is simply a place marker for any content to be placed in the header you could simply do this:-

<DataGridTextColumn.Header>
  <TextBlock Text="{Binding Path=Dummy,Source={StaticResource languagingSource},Converter={StaticResource languagingConverter},ConverterParameter=vehicleDescription}" />
</DataGridTextColumn.Header>
AnthonyWJones
Thanks for this; a simpler solution than presented in the thread I mention in my answer.
Steve Crane