让 IsMouseOver= "True"触发效果在鼠标关闭后也会保留片刻



当我将鼠标放在第一张图像上时,会出现第二张图像。当我将鼠标留在第一张图像上时,第二张图像将立即淡出。如何使第二张图像即使在第一张图像上关闭鼠标后仍显示几秒钟?

<EventTrigger RoutedEvent="Button.Click" SourceName="P">
    <EventTrigger.Actions>
        <BeginStoryboard Storyboard="{StaticResource showA}"/>
    </EventTrigger.Actions>
</EventTrigger>
<Button Grid.Column="1" Command="{Binding Path=PressC}" CommandParameter="cam" Style="{StaticResource TransparentButton}">
            <Button.Template>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Image Name="1" Source="/W;component/Images/1.png" Height="100" />
                        <Image Name="2" Source="/W;component/Images/2.png" Height="200" Width="100" Margin="50,-33,-50,0" Visibility="Hidden" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">          
                            <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="imgPressedKeyboard05" Storyboard.TargetProperty="Opacity" From="0" To="2" Duration="0:0:.5" BeginTime="0:0:0"/>
                                            <DoubleAnimation Storyboard.TargetName="imgPressedKeyboard05" Storyboard.TargetProperty="Opacity" From="2" To="0" Duration="0:0:.5" BeginTime="0:0:1"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                            <Setter Property="Panel.ZIndex" Value="999"/>                           
                            <Setter TargetName="pressed5" Property="Visibility" Value="Visible"/>                                    
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>

使用动画而不是简单的Setter。一个在EnterActions中使其可见,一个在ExitActions中以在给定时间后隐藏它。要对Visibility进行动画处理,您可以使用 ObjectAnimationUsingKeyFrames

最新更新