Using DataTrigger with more than one values in WPF Using DataTrigger with more than one values in WPF wpf wpf

Using DataTrigger with more than one values in WPF


MultiDataTrigger applies when all of the conditions are met not any, that's why your MultiDataTrigger isn't working.

Either have four separate triggers, or put the condition into a separate boolean property such as

bool ShowAssessment{    return Value == 301 || Value == 302 ...}

raise a property change notification for ShowAssessment when Value changes

e.g

int Value {     get{ return _value; }     set {         _value = value;         RaisePropertyChanged("Value");        RaisePropertyChanged("ShowAssessment");    }}

and then trigger on ShowAssessment.

Probably a better solution is to add a HeaderText property with a switch statement that returns the correct header text based on Value. Then just bind the header's text to that. No triggers required.


MultidataTrigger will act when all condition are satisfied . So

<MultiDataTrigger>    <MultiDataTrigger.Conditions>        <Condition Binding="{Binding Path=Prop1}" Value="301"/>        <Condition Binding="{Binding Path=Prop2}" Value="301"/>        <Condition Binding="{Binding Path=Prop3}" Value="302"/>        <Condition Binding="{Binding Path=Prop4}" Value="303"/>    </MultiDataTrigger.Conditions>    <Setter Property="Header" TargetName="expanderHeader" Value="Assessment"/></MultiDataTrigger>

You will require a single DataTrigger

<DataTrigger Binding="{Binding Path=ConditionEnum}" Value="1">    <Setter Property="Header" TargetName="expanderHeader" Value="Course Text"/></DataTrigger>

Set the Value of the Enum with a Defined logic in your code...

Example :

Validate(){    if(Value == 301 || Value == 302|| ....)    {        ConditionEnum = MyEnum.Assessment;    }    //Other Conditions}

I am leaving the implementation of INotifyPropertyChanged. Use it to provide change notifications.