所以,這是我的Datagrid在DataGridTextColumn無法更改前景
<DataGrid AutoGenerateColumns="false" Height="270" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="503" ItemsSource="{Binding Path=MyVocabularyExam, Mode=TwoWay}" CanUserAddRows="False" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" SelectionMode="Single" SelectionUnit="Cell" >
<DataGrid.Columns>
<DataGridTextColumn x:Name="Sprache1" Width="*" Header="Sprache1" Binding="{Binding Language1}" IsReadOnly="True" />
<DataGridTextColumn x:Name="Sprache2" Width="*" Header="Sprache2" Binding="{Binding Language2, Mode=TwoWay}" IsReadOnly="False" Foreground="{Binding LanguageColor}"/>
</DataGrid.Columns>
</DataGrid>
I'm綁定列表到DataGrid具有以下屬性
public class myVocabulary
{
public string Language1 { get; set; }
public string Language2 { get; set; }
public SolidColorBrush LanguageColor { get; set; }
}
現在我想打一個詞彙考試。第一列填寫單詞,另一列填寫翻譯。 我唯一的問題是,我無法更改用戶輸入的錯誤翻譯的前景。 用戶填好網格後,他必須點擊一個按鈕,它會檢查一切是否正確。錯誤的單詞必須變成紅色。
我試圖
MyVocabularyExam [I] .LanguageColor = Brushes.Red;
MyVocabularyExam [i] .LanguageColor = new SolidColorBrush(Colors.Red);
但是沒有奏效。 所以,請幫助我的人^^
查看http://stackoverflow.com/questions/1745132/how-do-i-change-the-background-color-of-a-cell-using-wpf-toolkit-datagrid – Mikhail