2011-03-15 14 views
2

これは簡単なことではないようですが、WPFのストーリーボードを一時停止することはできません。私はPauseと呼びますが、何も起こりません。その幅をアニメーションボタン:ストーリーボードを一時停止するにはどうすればよいですか?

はここREPROケースです。ボタンをクリックすると、ストーリーボードのPauseが呼び出されます。私は、ボタンをクリックするとすぐに、その幅が変わらないことを期待しています。代わりに、私はPauseを呼び出さなかったかのように、アニメーションの幅をそのまま維持します。私は、ドキュメントの理解何から

NameScope.SetNameScope(this, new NameScope()); 
var storyboard = new Storyboard(); 

var button = new Button { Content = "Pause", Name = "pause" }; 
this.Content = button; 
RegisterName(button.Name, button); 
var animation = new DoubleAnimation(0, 200, TimeSpan.FromSeconds(5)); 
Storyboard.SetTargetName(animation, button.Name); 
Storyboard.SetTargetProperty(animation, 
    new PropertyPath(FrameworkElement.WidthProperty)); 
storyboard.Children.Add(animation); 

button.Click += (sender, e) => { storyboard.Pause(this); }; 
storyboard.Begin(this); 

、私は、それゆえPause(this)以上、私はBeginに渡され、同じパラメータでPause(FrameworkElement)オーバーロードを呼び出す必要があります。しかし、私もstoryboard.Pause()を試しました。振る舞いは変わりません。私もstoryboard.Pause(button)を試してみましたが、もう一度効果はありません。私は可能性を排気するstoryboard.Pause(storyboard)storyboard.Pause(animation)を試してみましただろうが、どちらも1はコンパイル - それはFrameworkElementの(またはFrameworkContentElementのを)望んでいます。

にはどうすればstoryboadを一時停止するのですか?

答えて

4

使用している、なぜ私はあなたのコードをクリアするなどSetNameScope weired私はそれを動作させることができることを知っていない:

 //NameScope.SetNameScope(this, new NameScope()); 
     var storyboard = new Storyboard(); 

     var button = new Button { Content = "Pause", Name = "pause" }; 
     this.Content = button; 
     //RegisterName(button.Name, button); 
     var animation = new DoubleAnimation(0, 200, TimeSpan.FromSeconds(5)); 
     Storyboard.SetTarget(animation, button); 
     Storyboard.SetTargetProperty(animation, 
      new PropertyPath(FrameworkElement.WidthProperty)); 
     storyboard.Children.Add(animation); 

     button.Click += (sender, e) => { storyboard.Pause(); }; 
     storyboard.Begin(); 
+0

はぁ。 MSDNドキュメントでは、名前スコープを設定する必要があると主張していますが、あなたのバージョンは(a)簡単であり、(b)は機能しています。買います。 –

+0

私は少しバッフル付きだと言っている..私は今、5年間のWPFをプログラミングしてきた、そしてそれは私が今までNameScopeの&RegisterNameの使い方を見てきた最初の時間です...: -/ –

+0

は次のようになります(a)SetTargetNameの代わりにSetTargetを使用し、(b) 'this'を渡すのではなく、パラメータのない' Begin'と 'Pause'を使用することです。 NameScopeは無害ですが、SetTargetを使用する場合は不要です。 –

関連する問題