有没有可能有一个按钮样式的故事板,将显示一个文本倒计时作为按钮内容?即按钮最初显示的内容=“OK(20)"。然后自动倒计时开始,将内容更改为“OK(19)",“OK(18)",...,“OK(0)",而在ViewModel中没有任何代码?
vuv7lop31#
使用VM中的属性,您可以更容易和正确地执行此操作。在不改变虚拟机的情况下,你可以动画文本,但需要考虑如何处理事件时,故事板将完成。
<Button Name="myAnimatedButton" Margin="200" FontSize="16pt" FontFamily="Verdana">Some Text <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <StringAnimationUsingKeyFrames Storyboard.TargetName="myAnimatedButton" Storyboard.TargetProperty="(Button.Content)" Duration="0:0:20" FillBehavior="HoldEnd"> <DiscreteStringKeyFrame Value="OK (20)" KeyTime="0:0:0" /> <DiscreteStringKeyFrame Value="OK (19)" KeyTime="0:0:1" /> <DiscreteStringKeyFrame Value="OK (18)" KeyTime="0:0:2" /> <DiscreteStringKeyFrame Value="OK (17)" KeyTime="0:0:3" /> <DiscreteStringKeyFrame Value="OK (16)" KeyTime="0:0:4" /> <DiscreteStringKeyFrame Value="OK (15)" KeyTime="0:0:5" /> <DiscreteStringKeyFrame Value="OK (14)" KeyTime="0:0:6" /> <DiscreteStringKeyFrame Value="OK (13)" KeyTime="0:0:7" /> <DiscreteStringKeyFrame Value="OK (12)" KeyTime="0:0:8" /> <DiscreteStringKeyFrame Value="OK (11)" KeyTime="0:0:9" /> <DiscreteStringKeyFrame Value="OK (10)" KeyTime="0:0:10" /> <DiscreteStringKeyFrame Value="OK (09)" KeyTime="0:0:11" /> <DiscreteStringKeyFrame Value="OK (08)" KeyTime="0:0:12" /> <DiscreteStringKeyFrame Value="OK (07)" KeyTime="0:0:13" /> <DiscreteStringKeyFrame Value="OK (06)" KeyTime="0:0:14" /> <DiscreteStringKeyFrame Value="OK (05)" KeyTime="0:0:15" /> <DiscreteStringKeyFrame Value="OK (04)" KeyTime="0:0:16" /> <DiscreteStringKeyFrame Value="OK (03)" KeyTime="0:0:17" /> <DiscreteStringKeyFrame Value="OK (02)" KeyTime="0:0:18" /> <DiscreteStringKeyFrame Value="OK (01)" KeyTime="0:0:19" /> <DiscreteStringKeyFrame Value="OK (0)" KeyTime="0:0:20" /> </StringAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button>
1条答案
按热度按时间vuv7lop31#
使用VM中的属性,您可以更容易和正确地执行此操作。
在不改变虚拟机的情况下,你可以动画文本,但需要考虑如何处理事件时,故事板将完成。