无法更改 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>
我使用以下属性将列表绑定到数据网格
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);
但这没有用。 所以请有人帮助我^^
So, this is my Datagrid
<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 binding a List to the Datagrid with following Properties
public class myVocabulary
{
public string Language1 { get; set; }
public string Language2 { get; set; }
public SolidColorBrush LanguageColor { get; set; }
}
Now I want to make an Vocabulary Exam. The first column is filled with words and the other Column have to be filled with the translation.
My only problem is, I can´t change the foreground of the wrong translations, which the user have typed.
After the user have filled the grid, he have to click on a button, which will check if everything is correct. The wrong words have to turn in a red color.
I have tried
MyVocabularyExam[i].LanguageColor = Brushes.Red;
MyVocabularyExam[i].LanguageColor = new SolidColorBrush(Colors.Red);
But that didn´t work.
So please someone help me ^^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须显式设置 ElementStyle 才能使其工作:
也许有更好的解决方案,但我此时停止搜索。
I had to set
ElementStyle
explicitly to make it work:Maybe there is a better solution, but I stopped searching at this point.