开发者

Pausing a Storyboard in WPF?

I'm gonna pause a Storyboard in WPF, so I've开发者_StackOverflow中文版 used below code :

Storyboard TheStoryboard;

//Constructor 
public window
{
    TheStoryboard = (Storyboard)this.FindResource("TheStoryboardName");
}

private void MenuItemPause_Click(object sender, RoutedEventArgs e)
{
    TheStoryboard.Pause();
}

But nothing happen!

What is the right way to do that ?


I've found the problem.
I've been added a trigger for beginning the storyboard as follows :

<Window.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
        <BeginStoryboard Storyboard="{StaticResource TheStoryboardName}"/>
    </EventTrigger>
</Window.Triggers>

I've omitted it, and added a C# code for beginning the storyboard :

Storyboard TheStoryboard;

//Constructor 
public window
{
    TheStoryboard = (Storyboard)this.FindResource("TheStoryboardName");
    TheStoryboardName.Begin();
}

Now , the following code works well.

private void MenuItemPause_Click(object sender, RoutedEventArgs e)
{
    TheStoryboard.Pause();
}


I encountered the same problem.

But it's wired that the behavior in .NET Framework 3.5 & 4 seems to be different.

I had a project which was built via .NET Framework 3.5 and then changed to .NET Framework 4.

In 3.5, I also had the trigger you mentioned to begin the storyboard. But I still could pause it in my code.

In 4, I couldn't pause the storyboard with the trigger.

So I moved it and now the storyboard work as I expect.

Thank you for your sharing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜