0
如何讓WPF的故事板在開始後的預定義時間停止/暫停?例如啓動後20秒?如何在開始後的預定義時間暫停/停止WPF的故事板?
如何讓WPF的故事板在開始後的預定義時間停止/暫停?例如啓動後20秒?如何在開始後的預定義時間暫停/停止WPF的故事板?
如果我正確地理解了你的問題,從我的項目中,我在定義的秒內將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);
}
預定義在12:32 PM或可能*開始後20秒*?你的問題不清楚.. – Blachshma
嗨Blachshma,我更新了我的問題,它是後者,它開始後的預定義時間。 –