I created a pivot in Xaml. The pivot has 4 items.
On every pivot there is a storyboard animation created by following code:
开发者_StackOverflow {
var myStoryBoard = new Storyboard();
myStoryBoard.RepeatBehavior = RepeatBehavior.Forever;
var animation = new ObjectAnimationUsingKeyFrames();
Storyboard.SetTarget(animation, myAnim1);
Storyboard.SetTargetProperty(animation, new PropertyPath("Source"));
myStoryBoard.Children.Add(animation);
// try to catch my images autmatically
for (int i = 1; i <= 12; i++)
{
var keyframe = new DiscreteObjectKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(750 * i)),
Value = String.Format("/Images/img_{0:D2}.jpg", i)
};
animation.KeyFrames.Add(keyframe);
}
Resources.Add("myAnimation", storyboard); }
How can I set the Begin of the Storyboard to start only if the pivot item is selected, while all other Storyboards are not playing?
I tried to set it with Pivot_SelectionChanged();
but without success.
I think you have to create all storyboards in the loading method of your page and then show or hide the storyboard.
public MainPage() { // Create storyboard1 // create storyboard2 ... }
Then with the Pivot_SelectionChanged method show or hide you storyboard
private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) { switch (((Pivot)sender).SelectedIndex) { case 0: storyboard1.Begin(); storyboard2.Stop(); break; case 1: storyboard2.Begin(); storyboard1.Stop(); break; } }
精彩评论