質問

.netコードからストーリーボードを停止および再起動する適切な方法は何ですか?

試しています...

myStory.Stop(this);

.Begin(this);への後続の呼び出しを期待しています。タイムラインからゼロから再起動しますが、代わりに、ストーリーボードは停止したところから再開します。

試しました

.Remove(this);

そして試しました

.Seek(TimeSpan.Zero); 

これも機能しませんでした。

詳細...ストーリーボードのサンプルを次に示します。

<Storyboard x:Key="overlay">
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textone" Storyboard.TargetProperty="(UIElement.Opacity)">
        <SplineDoubleKeyFrame KeyTime="00:00:03.0" Value="0"/>
        <SplineDoubleKeyFrame KeyTime="00:00:03.0" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:06.0" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:06.0" Value="0"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="texttwo" Storyboard.TargetProperty="(UIElement.Opacity)">
        <SplineDoubleKeyFrame KeyTime="00:00:07.0" Value="0"/>
        <SplineDoubleKeyFrame KeyTime="00:00:07.0" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:10.0" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:10.0" Value="0"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

したがって、textoneのテキストが実行され、画面を閉じてすぐに画面に戻ると、texttwoが実際に新しく開始されたストーリーボード上で再生されます。そのため、元の(最初の画面から)ストーリーボードは、削除して停止したにもかかわらず、まだ使用されています。

役に立ちましたか?

解決

Storyboard.Seek(TimeSpan.Zero)の使用はどうですか?ストリームでのシークと同様に、これによりアニメーションの最初に戻ります。

IsControllableプロパティがtrueに設定されていることも確認する必要があるとコメントしました。それを覚えておいてください!

Storyboard.Seekメソッド

他のヒント

myStory.Begin(this)を呼び出す前にmyStory.Remove(this)を実行して、最初からやり直す必要があります。これは、Storyboard :: Stopを呼び出すとアニメーションクロックが停止するだけで、そのまま残るためです。その後のBeginへの呼び出しは、単に履歴書として機能します。これはやや直観に反することに同意しますが、ドキュメント ClockController :: Stop を使用すると、次のコメントが表示されます。

  

このメソッドは、ターゲットクロックの   CurrentStateを停止しました。

     

停止したクロックは次の方法で再起動できます   Begin、Seek、または   SeekAlignedToLastTickメソッド。

申し訳ありませんが、スコット、私は注意を払っていませんでした。ストーリーボードでFillBehaviorを設定しようとしましたか。 FillBehaviorをStopに設定すると、アニメーションがリセットされます。なぜStopがそれをしないのかわからない...

<Storyboard x:Key="overlay">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textone" Storyboard.TargetProperty="(UIElement.Opacity)">
    <SplineDoubleKeyFrame KeyTime="00:00:03.0" Value="0"/>
    <SplineDoubleKeyFrame KeyTime="00:00:03.0" Value="1"/>
    <SplineDoubleKeyFrame KeyTime="00:00:06.0" Value="1"/>
    <SplineDoubleKeyFrame KeyTime="00:00:06.0" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="texttwo" Storyboard.TargetProperty="(UIElement.Opacity)">
    <SplineDoubleKeyFrame KeyTime="00:00:07.0" Value="0"/>
    <SplineDoubleKeyFrame KeyTime="00:00:07.0" Value="1"/>
    <SplineDoubleKeyFrame KeyTime="00:00:10.0" Value="1"/>
    <SplineDoubleKeyFrame KeyTime="00:00:10.0" Value="0"/>
</DoubleAnimationUsingKeyFrames>

 using System.Windows.Media.Animation;

次に、新しいストーリーボードを作成します

 Storyboard storyboard_name = (Storyboard)(FindResource("overlay")); 
 storyboard_name.Begin();

ストーリーボード&quot; storyboard_name&quot;開始します。

ストーリーボードを停止する場合は、次のようにしてください

storyboard_name.Stop();

ストーリーボードを削除する場合は、次のようにしてください

storyboard_name.Remove();

その他の詳細は次のとおりです。

this.MyAnimation.FillBehavior = FillBehavior.Stop;

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top