我正在使用 .NET 3.5
我有一个 DataGridTextColumn,当该列的值为 false 时,我想将背景颜色变为红色。我已经在 XMAL 中看到了这一点,但无法弄清楚如何在后面的代码中做到这一点
DataGridTextColumn column = new DataGridTextColumn() { Header = "Can Connect", Binding = new Binding("CanConnect") };
//How to add the converter here so that the background of the cell turns red when CanConnect = false?
public class IsConnectedConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool input = (bool)value;
switch (input)
{
case true:
return DependencyProperty.UnsetValue;
default:
return Brushes.Red;
}
}
}