I was just starting to look into WPF, and I ran into an interesting problem. The goal is to have a simple form with a single button, when the user clicks on the mouse button, the button should go away, so let's say that the whole process is as follows: 1. The button is in position A. 2. Move the mouse cursor over the button B. 3. Move the cursor over the button to move it to position C. 4. Move the mouse cursor over the button that will return to position A. 5. The mouse above the button will again move to position B.
The goal is that the user can never press a button that runs between A and B from C to A to B, and it should be continued until the user refuses. I am trying to achieve this using triggers and animations; the problem is that triggers only work once, after the button has returned to position. The trigger does not fire a second time, so the button no longer moves. Here is the code from the xaml file.
<Window x:Class="Test_1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="Button">
<Style.Triggers>
<MultiTrigger x:Name="Aaaa" >
<MultiTrigger.Conditions>
<Condition Property="Margin" Value="51,58,0,0"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Name="SB2" >
<Storyboard Duration="0:0:1">
<ThicknessAnimation Storyboard.TargetProperty="Margin" To="249,199,0,0" />
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
</MultiTrigger>
<MultiTrigger x:Name="Bbbbb">
<MultiTrigger.Conditions>
<Condition Property="Margin" Value="249,199,0,0"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Name="SB3">
<Storyboard Duration="0:0:1">
<ThicknessAnimation Storyboard.TargetProperty="Margin" To="301,66,0,0" />
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
</MultiTrigger>
<MultiTrigger x:Name="Ccccc">
<MultiTrigger.Conditions>
<Condition Property="Margin" Value="301,66,0,0"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Name="SB4">
<Storyboard Duration="0:0:1">
<ThicknessAnimation Storyboard.TargetProperty="Margin" To="51,58,0,0"/>
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
</MultiTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="51,58,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
</Grid>
Thank!
source
share