0

当鼠标移到矩形上时,我想在矩形上显示带有一些动画的用户控件,重置动画并在鼠标离开时折叠用户控件。

我的问题是我应该如何“重置”动画,因为我当前的方法只是在鼠标离开时折叠用户控件。下面是我的演示代码。

编辑:

控件库.xaml

<UserControl.Style>
    <Style>
      <Style.Triggers>
       <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                <BeginStoryboard Name="opacityStoryBoard">
                    <Storyboard  >
                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:10" From="0" To="2" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>

            <EventTrigger RoutedEvent="FrameworkElement.MouseLeave">
                <SeekStoryboard BeginStoryboardName="opacityStoryBoard" Offset="00:00:00">  </SeekStoryboard>
            </EventTrigger>

            <Trigger Property="FrameworkElement.Visibility" Value="Collapsed">
                <Setter Property="FrameworkElement.Opacity" Value="0"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</UserControl.Style>

<StackPanel Orientation="Vertical">
    <Label Content="Welcome" HorizontalAlignment="Stretch" VerticalAlignment="Top"
    HorizontalContentAlignment="Center" VerticalContentAlignment="Center" 
    Foreground="White"  Background="Transparent" FontSize="25" Height="300" Margin="10,0" />

    <!--<Image Height="300" x:Name="qr" Margin="10,0"  />-->


 </StackPanel>   


主窗口.xaml

<myToolTip:UserControl1 Visibility="Collapsed" 
        x:Name="customToolTip" />

    <Rectangle Fill="Transparent" HorizontalAlignment="Left" Height="322" Stroke="Black" 
       VerticalAlignment="Top" Width="518" MouseMove="Rectangle_MouseMove_1"   MouseLeave="Rectangle_MouseLeave_1">
    </Rectangle>

主窗口.cs

      private void Rectangle_MouseMove_1(object sender, MouseEventArgs e)
    {

        customToolTip.Visibility = System.Windows.Visibility.Visible;

    }

    private void Rectangle_MouseLeave_1(object sender, MouseEventArgs e)
    {
        customToolTip.Visibility = System.Windows.Visibility.Collapsed;
    }

请指导我..谢谢。

4

1 回答 1

1

当鼠标离开矩形时,使用SeekStoryBoard该类重置动画时间。

例如:

<Style.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Name="opacityStoryBoard">
                    <Storyboard  >
                        <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="00:00:10" From="0" To="2" />
                    </Storyboard>
            </BeginStoryboard>
    </EventTrigger>
    <Trigger Property="FrameworkElement.Visibility" Value="Collapsed">
            <Setter Property="FrameworkElement.Opacity" Value="0"/>
            <Trigger.EnterActions>
                    <SeekStoryboard BeginStoryboardName="opacityStoryBoard" Offset="00:00:00"></SeekStoryboard>
            </Trigger.EnterActions>
    </Trigger>
</Style.Triggers>
于 2012-12-27T08:35:25.330 回答