I have a StackPanel control, it has an Image located centrally and vertically in the center.
There are 2 MouseMove and MouseLeave events bound to the StackPanel. When I mouse over the Image, the animation is triggered, but when I drag the mouse off the Image, the reverse animation process takes place which is located in MouseLeave (StackPanel). Tobish animation gets lost, although the Image is in the StackPanel. How can I make sure that the MouseLeave method in StackPanel is not called when the cursor is removed from Image? Help plz!
<Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication2" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <StackPanel Background="Red" MouseMove="StackPanel_MouseMove" MouseLeave="StackPanel_MouseLeave"> <Image x:Name="Image1" Source="icons8-папка-50.png" Opacity="0.5" Margin="0, 50, 0, 0" HorizontalAlignment="Center" Height="100" /> </StackPanel> <Button Grid.Row="1"/> </Grid> private void StackPanel_MouseMove(object sender, MouseEventArgs e) { DoubleAnimation anim = new DoubleAnimation(Image1.Opacity, 1, TimeSpan.FromSeconds(1)); Image1.BeginAnimation(Image.OpacityProperty, anim); } private void StackPanel_MouseLeave(object sender, MouseEventArgs e) { DoubleAnimation anim = new DoubleAnimation(Image1.Opacity, 0.5, TimeSpan.FromSeconds(1)); Image1.BeginAnimation(Image.OpacityProperty, anim); }