2013-01-21 28 views

回答

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); 
    } 
相關問題