Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Trigger not null

Tags:

wpf

triggers

How to trigger an action in WPF when the Property is not null? This is a working solution when is null:

<Style.Triggers>
    <DataTrigger Binding="{Binding}" Value="{x:Null}">

      <Setter Property="Background" Value="Yellow" />

    </DataTrigger>
</Style.Triggers>

I know that you cant "turn around" the condition and do what you need, but want to know

like image 243
theSpyCry Avatar asked Aug 06 '09 09:08

theSpyCry


1 Answers

Unfortunately, you can't. But actually it's not necessary : you just need to specify the background for when the value is not null in the style setters, not in the trigger :

<Style.Setters>
    <!-- Background when value is not null -->
    <Setter Property="Background" Value="Blue" />
</Style.Setters>
<Style.Triggers>
    <DataTrigger Binding="{Binding}" Value="{x:Null}">

      <Setter Property="Background" Value="Yellow" />

    </DataTrigger>
</Style.Triggers>
like image 94
Thomas Levesque Avatar answered Nov 08 '22 20:11

Thomas Levesque