Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Can';t更改DataGridTextColumn中的前景_Asp.net_Wpfdatagrid - Fatal编程技术网

Asp.net Can';t更改DataGridTextColumn中的前景

Asp.net Can';t更改DataGridTextColumn中的前景,asp.net,wpfdatagrid,Asp.net,Wpfdatagrid,所以,这是我的数据网格 <DataGrid AutoGenerateColumns="false" Height="270" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="503" ItemsSource="{Binding Path=MyVocabularyExam, Mode=TwoWay}" CanUserAddRows="False" CanUserResizeColum

所以,这是我的数据网格

    <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>
现在我想做一个词汇考试。第一列填单词,另一列填译文。 我唯一的问题是,我无法更改用户键入的错误翻译的前景。 在用户填写完表格后,他必须单击一个按钮,该按钮将检查所有内容是否正确。错误的单词必须变成红色

我试过了

MyVocabulary考试[i]。语言颜色=画笔。红色

MyVocabularyExam[i].LanguageColor=新的SolidColorBrush(Colors.Red)

但这不起作用。
所以请有人帮帮我^ ^

我必须明确地设置
ElementStyle
才能使它工作:

<DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
         <Setter Property="Foreground"
                 Value="{Binding Path=FontColor}"></Setter>
    </Style>
</DataGridTextColumn.ElementStyle>


也许有更好的解决方案,但我现在停止了搜索。

我必须显式设置
ElementStyle
,以使其工作:

<DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
         <Setter Property="Foreground"
                 Value="{Binding Path=FontColor}"></Setter>
    </Style>
</DataGridTextColumn.ElementStyle>

也许有更好的解决方案,但我现在停止了搜索。

请参阅