StopStoryboard 不...停止 BeginStoryboard

发布于 2024-12-12 07:16:40 字数 1533 浏览 0 评论 0原文

我从我的项目中提取了这段代码,因为我试图找到我犯的一个错误,该错误使我的 BeginStoryboard 无法自行停止。我尽可能地简化了代码,但仍然没有发现问题。你认为它可能是什么?

<Window Width="640" Height="480" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<StackPanel>
    <Button Content="Start" Name="Button" Width="200">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
                <BeginStoryboard Name="Storyboard">
                    <Storyboard>
                        <DoubleAnimation By="150" Duration="0:0:5" Storyboard.TargetName="Button" Storyboard.TargetProperty="Width"/>
                        <StringAnimationUsingKeyFrames Storyboard.TargetName="Button" Storyboard.TargetProperty="Content">
                            <DiscreteStringKeyFrame KeyTime="0:0:5" Value="Did you click? Because I obviously didn't stop..."/>
                        </StringAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Button.Triggers>
    </Button>
    <Button Content="Stop">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
                <StopStoryboard BeginStoryboardName="Storyboard"/>
            </EventTrigger>
        </Button.Triggers>
    </Button>
</StackPanel>
</Window>

自己尝试一下代码,第一个按钮触发故事板,第二个按钮应该停止它,但没有任何反应,所以第一个按钮中的动画愉快地进行。

I have extracted this piece of code from my project, because I was trying to find a mistake I made which keeps my BeginStoryboard from stopping itself. I simplified code as much as possible and still I don't see a problem. What do you think it could be?

<Window Width="640" Height="480" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<StackPanel>
    <Button Content="Start" Name="Button" Width="200">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
                <BeginStoryboard Name="Storyboard">
                    <Storyboard>
                        <DoubleAnimation By="150" Duration="0:0:5" Storyboard.TargetName="Button" Storyboard.TargetProperty="Width"/>
                        <StringAnimationUsingKeyFrames Storyboard.TargetName="Button" Storyboard.TargetProperty="Content">
                            <DiscreteStringKeyFrame KeyTime="0:0:5" Value="Did you click? Because I obviously didn't stop..."/>
                        </StringAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Button.Triggers>
    </Button>
    <Button Content="Stop">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
                <StopStoryboard BeginStoryboardName="Storyboard"/>
            </EventTrigger>
        </Button.Triggers>
    </Button>
</StackPanel>
</Window>

Try the code yourself, first Button triggers the storyboard, second one is supposed to stop it, but nothing happens, so animation in first Button goes on happily.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零時差 2024-12-19 07:16:40

您的 BeginStoryboard 位于不同的命名范围中,因此 StopStoryboard 看不到它。

您需要将两个触发器放在同一个集合中,例如 MSDN 示例

Your BeginStoryboard is in a different naming scope, so the StopStoryboard doesn't see it.

You need to put both triggers in the same collection, like the MSDN example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文