WPFのストーリーボードを、開始後の事前定義された時間に停止/一時停止するにはどうすればよいですか?たとえば、開始から20秒後?
質問する
310 次
1 に答える
0
私があなたの質問を正しく理解していれば、私のプロジェクトから、定義された秒数で UI 要素をある要素から別の要素にスムーズに変更します。
void ScreenSelector(FrameworkElement CurrentElement, FrameworkElement ToNextElement, bool Side)
{
if (_Storyboard != null) _Storyboard.Stop(this);
Thickness _TicknessLeft = new Thickness(Width, 0, -Width, 0);
Thickness _TicknessRight = new Thickness(-Width, 0, Width, 0);
Thickness _TicknessClient = new Thickness(0, 0, 0, 0);
TimeSpan _TimeSpanStarting = TimeSpan.FromSeconds(0);
TimeSpan _TimeSpanStopping = TimeSpan.FromSeconds(0.5);
KeyTime _KeyTimeStarting = KeyTime.FromTimeSpan(_TimeSpanStarting);
KeyTime _KeyTimeStopping = KeyTime.FromTimeSpan(_TimeSpanStopping);
ToNextElement.Margin = Side ? _TicknessRight : _TicknessLeft;
ToNextElement.Visibility = Visibility.Visible;
Storyboard _StoryboardTemp = new Storyboard();
ThicknessAnimationUsingKeyFrames _CurrentThicknessAnimationUsingKeyFrames = new ThicknessAnimationUsingKeyFrames();
_CurrentThicknessAnimationUsingKeyFrames.BeginTime = _TimeSpanStarting;
Storyboard.SetTargetName(_CurrentThicknessAnimationUsingKeyFrames, CurrentElement.Name);
Storyboard.SetTargetProperty(_CurrentThicknessAnimationUsingKeyFrames, new PropertyPath("(FrameworkElement.Margin)"));
_CurrentThicknessAnimationUsingKeyFrames.KeyFrames.Add(new SplineThicknessKeyFrame(_TicknessClient, _KeyTimeStarting));
_CurrentThicknessAnimationUsingKeyFrames.KeyFrames.Add(new SplineThicknessKeyFrame(Side ? _TicknessLeft : _TicknessRight, _KeyTimeStopping));
_StoryboardTemp.Children.Add(_CurrentThicknessAnimationUsingKeyFrames);
ThicknessAnimationUsingKeyFrames _NextThicknessAnimationUsingKeyFrames = new ThicknessAnimationUsingKeyFrames();
_NextThicknessAnimationUsingKeyFrames.BeginTime = _TimeSpanStarting;
Storyboard.SetTargetName(_NextThicknessAnimationUsingKeyFrames, ToNextElement.Name);
Storyboard.SetTargetProperty(_NextThicknessAnimationUsingKeyFrames, new PropertyPath("(FrameworkElement.Margin)"));
_NextThicknessAnimationUsingKeyFrames.KeyFrames.Add(new SplineThicknessKeyFrame(Side ? _TicknessRight : _TicknessLeft, _KeyTimeStarting));
_NextThicknessAnimationUsingKeyFrames.KeyFrames.Add(new SplineThicknessKeyFrame(_TicknessClient, _KeyTimeStopping));
_StoryboardTemp.Children.Add(_NextThicknessAnimationUsingKeyFrames);
_StoryboardTemp.Completed += (EventHandler)delegate(object sender, EventArgs e)
{
CurrentElement.Visibility = Visibility.Hidden;
_Storyboard = null;
};
_Storyboard = _StoryboardTemp;
BeginStoryboard(_StoryboardTemp);
}
于 2013-01-21T21:37:58.030 に答える