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>
Don't know why this is being voted down, it's a perfectly valid question.
In general you do this by assigning default Setters in a Style and then only using DataTriggers to override these in response to specific values, ie:
<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>
There is no !=
operator available in XAML so you will have to use a converter or you could add and bind to another source property where you implement the logic, e.g.:
<DataTrigger Binding="{Binding IsAssigned}" Value="True">
...
public bool IsAssigned => delivery_boy != "Not Assigned";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With