I have a WPF application with an expander where I want the IsExpanded property to change based on an enum value in my view model i.e. I want the expander to open or close based on this enum property. I am using data triggers in the xaml to update the IsExpanded property based on the value of my enum backing property.
<Expander Header="Information and Procedures"
BorderThickness="0"
Margin="5">
<Expander.Style>
<Style TargetType="{x:Type Expander}" BasedOn="{StaticResource MetroExpander}">
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.Item.Match, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}, Mode=TwoWay}"
Value="{x:Static enum:Match.Multiple}">
<Setter Property="IsExpanded" Value="False"/>
</DataTrigger>
<DataTrigger Binding="{Binding DataContext.Item.Match, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}, Mode=TwoWay}"
Value="{x:Static enum:Match.None}">
<Setter Property="IsExpanded" Value="True"/>
</DataTrigger>
<DataTrigger Binding="{Binding DataContext.Item.Match, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}, Mode=TwoWay}"
Value="{x:Static enum:Match.Exact}">
<Setter Property="IsExpanded" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Expander.Style>
<WrapPanel Orientation="Horizontal" Background="Transparent">
<view:InformationView Margin="0 0 20 0"/>
<view:ProceduresView Margin="0 0 0 0" />
</WrapPanel>
</Expander>
This seems to work until we manually expand the expander. After this it seems as if the data triggers are now ignored and the manually set IsExpanded property will not change until the user manually opens or closes the expander again.
I want the user to be able to manually expand or close it, but I want the data triggers to take priority over the user input.
Note: I don't want the value of Match to be changed by the IsExpanded property. Match is updated separately, but its value affects IsExpanded