添加一个转换器是这样的:
namespace System.Converters
{
//Converter for cell animation
public class flashConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string cellvalue = value.ToString();
return cellvalue = ("place the condition here");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return false;
}
}
在你的 MainWindow.xaml.cs 添加命名空间
xmlns:loc="clr-namespace:YourProjectName.Converters"
在您的资源中添加以下内容:
<DataGrid.Resources>
<loc:flashConverter x:Key="SomeConverter"></loc:flashConverter>
</DataGrid.Resources>
在您的 DatagridTextColumn 添加以下内容:
<DataGridTextColumn Header="yourDatagridHeader" IsReadOnly="True" Binding="{Binding Path=yourDatagridHeader}">
<DataGridTextColumn.ElementStyle>
<!--Style to implement the datagrid cell animation for yourDatagridcell-->
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding yourDatagridHeader}" Value="Give your condition here">
<!-#E6F85050 is the hexadecimal value for RED-->
<Setter Property="Background" Value="#E6F85050"/>
</DataTrigger>
<DataTrigger Binding="{Binding yourDatagridHeader}" Value="Give your condition here">
<Setter Property="Background" Value="give the hexadecimal value for transparent here "/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
希望这可以帮助 !