如何在值不等于的情况下使用数据触发器

How to use data trigger in case of value not equal to

I have a Column 'Delivery Boy' in a data grid which is bind with a list in code behind. Values of DataGrid change dynamically.

<DataTrigger Binding="{Binding Path=delivery_boy}" Value="Not Assigned">
   <Setter Property="Foreground" Value="DarkRed"/>
   <Setter Property="Background" Value="Transparent"/>
</DataTrigger>

I can use 'Value' equals to in data trigger, how can I use data trigger for a case where I want the 'Value' property to be 'not equal to'

<DataTrigger Binding="{Binding Path=delivery_boy}" Value!="Not Assigned">
    <Setter Property="Foreground" Value="White"/>
    <Setter Property="Background" Value="Green"/>
</DataTrigger>

不知道为什么这个问题被否决了,这是一个完全有效的问题。

通常,您通过在 Style 中分配默认设置器,然后仅使用 DataTriggers 来覆盖这些以响应特定值,即:

<Style>
    <Setter Property="Foreground" Value="White"/>  <!-- Default value -->
    <Setter Property="Background" Value="Green"/>  <!-- Default value -->

    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=delivery_boy}" Value="Not Assigned">
            <Setter Property="Foreground" Value="DarkRed"/>
            <Setter Property="Background" Value="Transparent"/>
        </DataTrigger>
    </Style.Triggers>

</Style>

XAML 中没有可用的 != 运算符,因此您必须使用 converter 或者您可以添加并绑定到您实施的另一个来源 属性逻辑,例如:

<DataTrigger Binding="{Binding IsAssigned}" Value="True">
...

public bool IsAssigned => delivery_boy != "Not Assigned";