开发者

Why does this binding display a class name?

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开发者_C百科},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.


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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜