2010-06-18 80 views
3

爲什麼這個工作...Silverlight的DataGridTemplateColumn與DataGridTextColumn

<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' 爲第二個。該問題適用於前景轉換器,綁定是好的。

回答

2

我認爲問題是DataGridTextColumn的Foreground屬性不是依賴項屬性,因此不能用於數據綁定。

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtextcolumn.foreground(v=VS.95).aspx

用於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

相關問題