Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use DataTrigger From Enum property?

So i have this Enum:

public enum Status
{
    Intermediate = 0,
    Valid,
    NotValid
}

My ViewModel:

public class MyData
{
   private Status _status;

   public Status Status 
   {
       get { return _status; }
       set
       {
           _status= value;
           OnPropertyChanged();

       }
}

My TextBox Style:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding Status.Valid}" Value="True"/>
    </MultiDataTrigger.Conditions>
    <Setter Property="Background" Value="LightSeaGreen" />
</MultiDataTrigger>

So this Status property is changing and i verify the it become Valid but still my TextBox Background color not changing. This style is define in other ResourceDictionary file. The name of this file is TextBox.xaml.

Other properties works fine, the reason i am asking is that i never try to write Trigger with enum so i even dont know how to do that.

like image 242
falukky Avatar asked Dec 24 '22 09:12

falukky


1 Answers

Try this:

<Condition Binding="{Binding Status}" Value="Valid"/>

Or

<Condition Binding="{Binding Status}" Value="{x:Static local:Status.Valid}"/>

...where local is mapped against the CLR namespace of Status.

xmlns:local="clr-namespace:WpfApplication1"
like image 154
mm8 Avatar answered Jan 06 '23 19:01

mm8