本文整理汇总了C#中System.Windows.FrameworkElement.BeginAnimation方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.BeginAnimation方法的具体用法?C# FrameworkElement.BeginAnimation怎么用?C# FrameworkElement.BeginAnimation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.BeginAnimation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunScaleAnimation
public static void RunScaleAnimation(FrameworkElement e)
{
var storyboard = new Storyboard();
var easeOut = new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.3 };
var startHeight = e.ActualHeight;
var startWidth = e.ActualWidth;
var growAnimationHOut = new DoubleAnimation(startHeight, startHeight * 1.05,
TimeSpan.FromMilliseconds(70)) { AutoReverse = true };
var growAnimationWOut = new DoubleAnimation(startWidth, startWidth * 1.05,
TimeSpan.FromMilliseconds(70)) { AutoReverse = true };
growAnimationHOut.EasingFunction = easeOut;
growAnimationWOut.EasingFunction = easeOut;
storyboard.Children.Add(growAnimationHOut);
storyboard.Children.Add(growAnimationWOut);
//remove the events after completed to ensure that the ScatterViewItem is resizable again
growAnimationWOut.Completed += delegate { e.BeginAnimation(FrameworkElement.WidthProperty, null); };
growAnimationHOut.Completed += delegate { e.BeginAnimation(FrameworkElement.HeightProperty, null); };
Storyboard.SetTargetProperty(growAnimationWOut, new PropertyPath(FrameworkElement.WidthProperty));
Storyboard.SetTargetProperty(growAnimationHOut, new PropertyPath(FrameworkElement.HeightProperty));
e.BeginStoryboard(storyboard);
}
示例2: SlideIn
static void SlideIn(FrameworkElement frameworkElement)
{
AnimationTimeline marginAnimation = CreateSlideInAnimation(frameworkElement);
frameworkElement.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation);
frameworkElement.Visibility = Visibility.Visible;
DisableHiddenFrameworkElement(frameworkElement);
}
示例3: MoveWithRotationAndFadeOut
public static void MoveWithRotationAndFadeOut(FrameworkElement element, Point to, double rotationAngle, double seconds, AnimationCompletedDelegate callback)
{
TransformGroup transformGroup = new TransformGroup();
transformGroup.Children.Add(new RotateTransform(rotationAngle, element.Width / 2, element.Height / 2));
Duration duration = new Duration(TimeSpan.FromSeconds(seconds));
DoubleAnimation animationX = new DoubleAnimation(to.X, duration);
DoubleAnimation animationY = new DoubleAnimation(to.Y, duration);
DoubleAnimation fadeOutAnimation = new DoubleAnimation
{
From = 1,
To = 0.4,
Duration = duration,
FillBehavior = FillBehavior.Stop
};
animationX.Completed += (sender, _) => callback(sender, _);
TranslateTransform trans = new TranslateTransform();
element.RenderTransform = transformGroup;
trans.BeginAnimation(TranslateTransform.XProperty, animationX);
trans.BeginAnimation(TranslateTransform.YProperty, animationY);
element.Opacity = 0.4;
element.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation);
transformGroup.Children.Add(trans);
}
示例4: AnimatableRootClockConnectionTest
public void AnimatableRootClockConnectionTest()
{
TestRootClock rootClock = new TestRootClock();
FrameworkElement element = new FrameworkElement();
element.SetAnimatableRootClock(new AnimatableRootClock(rootClock, false));
Assert.AreEqual(0, rootClock.Clocks.Count());
Assert.IsFalse(element.IsVisible);
element.IsRootElement = true;
Assert.IsTrue(element.IsVisible);
DoubleAnimation animation = new DoubleAnimation { From = 0, To = 1 };
element.BeginAnimation(FrameworkElement.WidthProperty, animation);
Assert.AreEqual(1, rootClock.Clocks.Count());
rootClock.Tick(TimeSpan.FromSeconds(0.1));
Assert.AreEqual(0.1, element.Width);
element.IsRootElement = false;
Assert.IsFalse(element.IsVisible);
Assert.AreEqual(0, rootClock.Clocks.Count());
rootClock.Tick(TimeSpan.FromSeconds(0.2));
Assert.AreEqual(0.1, element.Width);
element.IsRootElement = true;
Assert.IsTrue(element.IsVisible);
Assert.AreEqual(1, rootClock.Clocks.Count());
Assert.AreEqual(0.2, element.Width);
rootClock.Tick(TimeSpan.FromSeconds(2));
Assert.AreEqual(0, rootClock.Clocks.Count());
element.IsRootElement = false;
element.IsRootElement = true;
Assert.AreEqual(0, rootClock.Clocks.Count());
}
示例5: FadeOut
public void FadeOut(FrameworkElement Change)
{
Change.BeginAnimation(UIElement.OpacityProperty, null);
DoubleAnimationUsingKeyFrames opacityAnimation = new DoubleAnimationUsingKeyFrames();
TimeSpan endTime = TimeSpan.FromSeconds(FadeOutDuration);
KeyTime kEnd = KeyTime.FromTimeSpan(endTime);
opacityAnimation.KeyFrames.Add(new SplineDoubleKeyFrame(FadeOutTo, kEnd));
Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("(FrameworkElement.Opacity)"));
Storyboard sb = new Storyboard();
sb.BeginTime = TimeSpan.FromMilliseconds(delay);
sb.Children.Add(opacityAnimation);
sb.Completed += (EventHandler)delegate(object sender, EventArgs e)
{
Change.Visibility = System.Windows.Visibility.Collapsed;
//Change.BeginAnimation(UIElement.OpacityProperty, null);
};
sb.Begin(Change);
}
示例6: animateCollapse
public static void animateCollapse(FrameworkElement elem, bool remove)
{
if (elem.DesiredSize.Height > 0)
{
elem.Height = elem.DesiredSize.Height;
DoubleAnimation pAnimation = createDoubleAnimation(0, 1000, false);
pAnimation.FillBehavior = FillBehavior.Stop;
pAnimation.Completed += delegate(object sender, EventArgs pEvent)
{
//elem.BeginAnimation(FrameworkElement.HeightProperty, null);
if (remove && elem.Parent is Panel)
{
((Panel)elem.Parent).Children.Remove(elem);
}
else
{
elem.Visibility = Visibility.Collapsed;
elem.Height = Double.NaN;
}
};
//pAnimation.Freeze();
elem.BeginAnimation(FrameworkElement.HeightProperty, pAnimation, HandoffBehavior.SnapshotAndReplace);
}
}
示例7: ApplyFadeOut
public static void ApplyFadeOut(FrameworkElement fe, Duration duration, Duration delay)
{
if (delay.TimeSpan == TimeSpan.Zero)
{
DoubleAnimation da = new DoubleAnimation(1.0, 0.0, duration);
fe.BeginAnimation(FrameworkElement.OpacityProperty, da);
}
else
{
DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
da.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KeyTime.FromTimeSpan(TimeSpan.Zero)));
da.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KeyTime.FromTimeSpan(delay.TimeSpan)));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(delay.TimeSpan + duration.TimeSpan)));
da.Duration = delay + duration;
fe.BeginAnimation(FrameworkElement.OpacityProperty, da);
}
}
示例8: Initialize
/// <summary>
/// 初始化整个布局
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <param name="layout"></param>
public static void Initialize(FrameworkElement left, FrameworkElement right, ParentChildProportion leftRightPercent = null)
{
//layout.AggtBlocks.Layout.ParentChildProportion
leftRightPercent = leftRightPercent ?? ParentChildProportion.Default;
ResizingPanelExt.SetStarGridLength(left, leftRightPercent.Parent);
ResizingPanelExt.SetStarGridLength(right, leftRightPercent.Children);
AnimationTimeline show = new DoubleAnimationUsingKeyFrames
{
KeyFrames = new DoubleKeyFrameCollection()
{
new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0))
},
new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)),
Value = leftRightPercent.Children,
EasingFunction = new ElasticEase
{
EasingMode = EasingMode.EaseOut,
Springiness = 10
}
}
}
};
AnimationTimeline hide = new DoubleAnimation()
{
From = leftRightPercent.Children,
Duration = new Duration(TimeSpan.FromMilliseconds(100)),
To = 0
};
//监听 childrenTab.VisiblityChanged 事件,播放动画效果
DependencyPropertyDescriptor.FromProperty(UIElement.VisibilityProperty, typeof(UIElement))
.AddValueChanged(right, (o, e) =>
{
right.BeginAnimation(
ResizingPanelExt.StarGridLengthProperty,
right.Visibility == Visibility.Visible ? show : hide
);
});
}
示例9: Animate
private void Animate(FrameworkElement obj, DependencyProperty property, double toValue, Duration duration)
{
double fromValue = (double)obj.GetValue(property);
if (double.IsNaN(fromValue))
fromValue = 0;
var animation = new DoubleAnimation(fromValue, toValue, duration, FillBehavior.HoldEnd)
{
AccelerationRatio = 0.3,
DecelerationRatio = 0.3
};
obj.BeginAnimation(property, animation);
}
示例10: animateSlide
public static void animateSlide(FrameworkElement item, bool reverse = false, bool vertical = true, double movement = 10, double duration = 1)
{
DoubleAnimation daOpacity = new DoubleAnimation();
DoubleAnimation daMovement = new DoubleAnimation();
if (!reverse)
{
daOpacity.From = 0;
daOpacity.To = 1;
daMovement.From = movement;
daMovement.To = 0;
}
else
{
daOpacity.From = 1;
daOpacity.To = 0;
daMovement.From = 0;
daMovement.To = movement;
}
daOpacity.Duration = TimeSpan.FromSeconds(duration);
daMovement.Duration = TimeSpan.FromSeconds(duration);
TranslateTransform tt = new TranslateTransform();
item.RenderTransform = tt;
CircleEase ease = new CircleEase();
ease.EasingMode = EasingMode.EaseOut;
daOpacity.EasingFunction = ease;
daMovement.EasingFunction = ease;
item.BeginAnimation(FrameworkElement.OpacityProperty, daOpacity);
if (vertical)
{
tt.BeginAnimation(TranslateTransform.YProperty, daMovement);
}
else
{
tt.BeginAnimation(TranslateTransform.XProperty, daMovement);
}
}
示例11: animateFade
public static void animateFade(FrameworkElement item, double from = 0, double to = 1, double duration = 1)
{
DoubleAnimation fader = new DoubleAnimation();
fader.From = from;
fader.To = to;
fader.Duration = TimeSpan.FromSeconds(duration);
item.BeginAnimation(FrameworkElement.OpacityProperty, fader);
}
示例12: MoveToNewView
private void MoveToNewView(FrameworkElement toViewElement, EventHandler outCompleted, EventHandler inCompleted)
{
if (_searchThread != null && _searchThread.IsAlive)
{
_searchThread.Abort();
}
var h = this.Height;
var durationOut = 0.3;
var durationIn = 0.2;
ThicknessAnimation animMoveOut = new ThicknessAnimation();
animMoveOut.BeginTime = TimeSpan.FromSeconds(0);
animMoveOut.Duration = TimeSpan.FromSeconds(durationOut);
animMoveOut.From = new Thickness(0, 0, 0, 0);
animMoveOut.To = new Thickness(0, h, 0, -h);
animMoveOut.FillBehavior = FillBehavior.Stop;
animMoveOut.EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseIn, Exponent = 2 };
animMoveOut.Completed += (s, e) =>
{
_currentViewElement.Visibility = System.Windows.Visibility.Collapsed;
if (outCompleted != null) outCompleted(s, e);
};
ThicknessAnimation animMoveIn = new ThicknessAnimation();
animMoveIn.BeginTime = TimeSpan.FromSeconds(durationOut + 0.05);
animMoveIn.Duration = TimeSpan.FromSeconds(durationIn);
animMoveIn.From = new Thickness(0, h, 0, -h);
animMoveIn.To = new Thickness(0, 0, 0, 0);
animMoveIn.FillBehavior = FillBehavior.Stop;
animMoveIn.EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseOut, Exponent = 2 };
animMoveIn.Completed += (s, e) =>
{
_currentViewElement = toViewElement;
toViewElement.Margin = new Thickness(0, 0, 0, 0);
if (inCompleted != null) inCompleted(s, e);
};
toViewElement.Margin = new Thickness(0, h, 0, -h);
toViewElement.Visibility = System.Windows.Visibility.Visible;
_currentViewElement.BeginAnimation(FrameworkElement.MarginProperty, animMoveOut);
toViewElement.BeginAnimation(FrameworkElement.MarginProperty, animMoveIn);
}
示例13: AnimateHighlightWidth
void AnimateHighlightWidth(FrameworkElement highlightFrameworkElement, DoubleAnimation widthDoubleAnimation)
{
if (highlightFrameworkElement == null) return;
widthDoubleAnimation.From = highlightFrameworkElement.ActualWidth;
widthDoubleAnimation.To = SelectedTabHeaderContentWidth;
highlightFrameworkElement.BeginAnimation(WidthProperty, widthDoubleAnimation);
}
示例14: MoveTTB
// TODO:움직이기 전 최초 좌표를 설정해줘야함. 지금은 임의로 -500값으로 진행중.
// 위쪽에서 등장
private void MoveTTB(FrameworkElement shape)
{
double x = shape.Margin.Left;
double y = shape.Margin.Top;
double yMove = 500;
PowerEase power = new PowerEase();
ThicknessAnimation linearAnimation = new ThicknessAnimation();
linearAnimation.From = new Thickness(x, y - yMove, 0, 0);
linearAnimation.To = new Thickness(x, y, 0, 0);
linearAnimation.EasingFunction = power;
shape.BeginAnimation(MarginProperty, linearAnimation);
}
示例15: FadeOut
// 어두워졌다가 밝아져서 형체가 사라진다.
private void FadeOut(FrameworkElement shape)
{
DoubleAnimation fadeOut = new DoubleAnimation(1.0, 0.0, TimeSpan.FromSeconds(1), FillBehavior.HoldEnd);
shape.BeginAnimation(OpacityProperty, fadeOut);
shape.Visibility = Visibility.Collapsed;
}