dxg:GridControl 单元格关联其他单元格的颜色设定

发布时间 2023-04-03 16:14:01作者: 梦寐以求じ

列样式:

<dxg:GridColumn.CellStyle>
<Style TargetType="{x:Type dxg:LightweightCellEditor}">
<Style.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource multiValueConverter}">
<Binding Path="RowData.Row.DogID" Converter="{StaticResource HardwareInfoConverter}"/>//对象集合
<Binding Path="RowData.Row.MacAddr" Converter="{StaticResource HardwareInfoConverter}"/>//对象集合
<Binding Path="RowData.Row.FileModified" Converter="{StaticResource ContentForegroundConverter}"/>//颜色值
<Binding Path="RowData.Row.FileInfoLack" Converter="{StaticResource ContentForegroundConverter}"/>
<Binding Path="RowData.Row.FileStandard" Converter="{StaticResource ContentForegroundConverter2}"/>
<Binding Path="RowData.Row.IsRegisteredName" Converter="{StaticResource ContentForegroundConverter2}"/>
<Binding Path="RowData.Row.EqualDogID" Converter="{StaticResource ContentForegroundConverter}"/>
<Binding Path="RowData.Row.EqualMacAddr" Converter="{StaticResource ContentForegroundConverter}"/>
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</dxg:GridColumn.CellStyle>

 

转换器:

public class MultiValueConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
try
{
if (values.Contains("Red"))
{
return true;
}
for (int i = 0; i < 2; i++)
{
var info = values[i] as List<HardwareInfoModel>;
if (info != null)
{
if (info.Find(n => n.IsSame == true) != null)
{
return true;
}
}
}
return false;
}
catch
{
return false;
}
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}