我使用.NET 3.5動態添加的IValueConverter在後面的代碼
我有,我想將背景色紅色,當該列的值是假的一個DataGridTextColumn。我已經看到了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;
}
}
}
只是將字符串「#FFFF0000」放入列單元格中的嗯。我如何定位背景顏色? – Bob
@Bob:啊,我假設你正在分配'Binding'對象的屬性已經是正確的了。在我看來,只能使用'Style'屬性設置背景顏色。請給我一點時間思考一些代碼。 –
@Bob:我已經更新了我的答案,並希望這個解決方案能夠工作:-) –