views:

85

answers:

1

I'm gonna pause a Storyboard in WPF, so I've 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 ?

A: 

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();
}
Mohammad