我们有一个自定义的ImageButton,按下按钮时我们会显示不同的图像。无论用户是否点击/触摸长按钮,我们都要求按钮保持活动状态1秒。我发现当用户释放点击或触摸时故事板停止。有没有办法不停止故事板并让它继续执行?试图指定一个多一点的持续时间,但没有帮助。以下是相关代码:
<Grid Name="MainGrid" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Stylus.IsPressAndHoldEnabled="False" Stylus.IsFlicksEnabled="False">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Pressed">
<Storyboard x:Name="VisualStatePressedStoryboard" Duration="0:0:1.1" >
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedImage" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames BeginTime="0:0:1" Storyboard.TargetName="PressedImage" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image Name="DefaultImage" Source="{TemplateBinding DefaultImageSource}" SnapsToDevicePixels="True" Stretch="Fill" >
</Image>
<Image Name="PressedImage" Source="{TemplateBinding PressedImageSource}" Stretch="Fill" SnapsToDevicePixels="True" Visibility="Hidden" />
</Grid>
我还尝试了很多其他东西,包括Trigger for IsPressed属性,EventTrigger for TouchDown事件等......
感谢,
答案 0 :(得分:0)
我使用数据触发器的EnterActions进行了操作,而没有指定退出操作:
<Trigger Property="IsPressedValue="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ShowPressedImageStoryboard}" x:Name="IsPressedEnterActionsStoryboard" />
</Trigger.EnterActions>
</Trigger>