为什么这样做......
<data:DataGridTemplateColumn Header="YTD v. Exchange" x:Name="YTDvExchange" Visibility="Collapsed" CanUserSort="True" SortMemberPath="ytdExchangeReturn.value">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextAlignment="Right" VerticalAlignment="Center"
Text="{Binding ytdExchangeReturn.value, Converter={StaticResource fcFixedDecimalConverter}}"
Foreground="{Binding ytdExchangeReturn.value, Converter={StaticResource fcForegroundValueConverter}}"/>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
但这不是......
<data:DataGridTextColumn Header="YTD v. Exchange"
Binding="{Binding ytdExchangeReturn.value, Converter={StaticResource fcFixedDecimalConverter}}"
Foreground="{Binding ytdExchangeReturn.value, Converter={StaticResource fcForegroundValueConverter}}"/>
我得到第二个'System.Windows.Markup.XamlParseException:AG_E_PARSER_BAD_PROPERTY_VALUE'。该问题适用于Foreground转换器,绑定很好。
答案 0 :(得分:2)
我认为问题是DataGridTextColumn的Foreground属性不是依赖属性,因此不能用于数据绑定。
用于CellTemplate的TextBlock的Foreground属性是依赖属性,因此是数据绑定的有效目标。
http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.foreground(v=vs.95).aspx
参考:
http://msdn.microsoft.com/en-us/library/cc221408(VS.95).aspx#setting_properties_data_binding
http://forums.silverlight.net/forums/p/151524/338879.aspx#338879