microsoft/XamlBehaviorsWpf

Reversibility of property changes for triggers

user98392 opened this issue · 3 comments

The problem is that we burdened to duplicate our triggers in order to restore state of properties.
For example, data triggers from WPF can do that.

There is not enough information in your issue to understand the problem you are having. Please provide more detail and a sample app to reproduce the issue.

So for example:

https://github.com/user98392/Example/blob/91e0ae747756109eb50c91e5a8f2c46246d2d808/MainWindow.xaml#L52-L60

Just for changing one property I need to have a pair of triggers where the second one is reverting back changes.
Is it possible to implement such reversibility for triggers?

Generally speaking, a DataTrigger will put properties back to their previous value when the specified condition is no longer true.

However, the same is not true for actions. There's no way for the trigger to know what action would "undo" the effect of the triggered action, assuming that there is even such an action.

For what you are trying to do, I would recommend using a Style Trigger instead. Remove the Button.Effect from your Button in MainWindow.xaml and update your ButtonStyle to use a trigger instead.

Something like this:

<Setter Property="Button.Effect">
    <Setter.Value>
        <DropShadowEffect ShadowDepth="0" Color="#36096D" />
    </Setter.Value>
</Setter>

<Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
        <Trigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="(Button.Effect).BlurRadius" To="20" Duration="0:0:0.2"/>
                </Storyboard>
            </BeginStoryboard>
        </Trigger.EnterActions>
        <Trigger.ExitActions>
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="(Button.Effect).BlurRadius" To="0" Duration="0:0:0.2"/>
                </Storyboard>
            </BeginStoryboard>
        </Trigger.ExitActions>
    </Trigger>
</Style.Triggers>