本文整理汇总了C#中this.BeginAnimation方法的典型用法代码示例。如果您正苦于以下问题:C# this.BeginAnimation方法的具体用法?C# this.BeginAnimation怎么用?C# this.BeginAnimation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.BeginAnimation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnimateImageSourceChange
public static void AnimateImageSourceChange(this Image image, ImageSource bitmap, Action<Image> onShowImage, AnimateImageChangeParams animateImageChangeParams = null)
{
var animationParameters = animateImageChangeParams ?? new AnimateImageChangeParams();
var fadeInAnimation = new DoubleAnimation(animationParameters.TargetOpacity, animationParameters.FadeTime);
if (image.Source != null)
{
var fadeOutAnimation = new DoubleAnimation(0d, animationParameters.FadeTime);
fadeOutAnimation.Completed += (o, e) =>
{
image.Source = bitmap;
onShowImage(image);
image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
};
image.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation);
}
else
{
image.Opacity = 0d;
image.Source = bitmap;
onShowImage(image);
image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
}
}
示例2: AnimateTo
/// <summary>
/// Animates the camera position and directions.
/// </summary>
/// <param name="camera">
/// The camera to animate.
/// </param>
/// <param name="newPosition">
/// The position to animate to.
/// </param>
/// <param name="newDirection">
/// The direction to animate to.
/// </param>
/// <param name="newUpDirection">
/// The up direction to animate to.
/// </param>
/// <param name="animationTime">
/// Animation time in milliseconds.
/// </param>
public static void AnimateTo(
this Camera camera,
Point3D newPosition,
Vector3D newDirection,
Vector3D newUpDirection,
double animationTime)
{
var projectionCamera = camera as ProjectionCamera;
if (projectionCamera == null)
{
return;
}
var fromPosition = projectionCamera.Position;
var fromDirection = projectionCamera.LookDirection;
var fromUpDirection = projectionCamera.UpDirection;
projectionCamera.Position = newPosition;
projectionCamera.LookDirection = newDirection;
projectionCamera.UpDirection = newUpDirection;
if (animationTime > 0)
{
var a1 = new Point3DAnimation(
fromPosition, newPosition, new Duration(TimeSpan.FromMilliseconds(animationTime)))
{
AccelerationRatio = 0.3,
DecelerationRatio = 0.5,
FillBehavior = FillBehavior.Stop
};
a1.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.PositionProperty, null); };
camera.BeginAnimation(ProjectionCamera.PositionProperty, a1);
var a2 = new Vector3DAnimation(
fromDirection, newDirection, new Duration(TimeSpan.FromMilliseconds(animationTime)))
{
AccelerationRatio = 0.3,
DecelerationRatio = 0.5,
FillBehavior = FillBehavior.Stop
};
a2.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, null); };
camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, a2);
var a3 = new Vector3DAnimation(
fromUpDirection, newUpDirection, new Duration(TimeSpan.FromMilliseconds(animationTime)))
{
AccelerationRatio = 0.3,
DecelerationRatio = 0.5,
FillBehavior = FillBehavior.Stop
};
a3.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, null); };
camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, a3);
}
}
示例3: animateHeight
public static void animateHeight(this UIElement element, DependencyProperty prop, double height, int mode)
{
double newHeight;
ElasticEase cc = new ElasticEase();
if (mode == 1)
{
newHeight = 260;
}
else if(mode == 2)
{
newHeight = 520;
}
else
{
newHeight = 0;
}
if(height != newHeight)
{
DoubleAnimation op = new DoubleAnimation(height, newHeight, program.tSpan);
cc.Springiness = 5;
cc.Oscillations = 1;
op.EasingFunction = cc;
cc.EasingMode = EasingMode.EaseInOut;
element.BeginAnimation(prop, op);
}
}
示例4: AnimateEase
public static void AnimateEase(this Animatable obj, DependencyProperty property, double fromValue, double toValue, TimeSpan duration)
{
var anim = new DoubleAnimation(fromValue, toValue, new Duration(duration));
anim.AccelerationRatio = 0.5;
anim.DecelerationRatio = 0.5;
obj.BeginAnimation(property, anim);
}
示例5: ShowwithAnimation
public static void ShowwithAnimation(this Window window)
{
window.Visibility = Visibility.Visible;
window.Topmost = false;
TimeSpan slidetime = TimeSpan.FromSeconds(0.3);
DoubleAnimation bottomAnimation = new DoubleAnimation();
bottomAnimation.Duration = new Duration(slidetime);
double top = window.Top;
bottomAnimation.From = window.Top + 25;
bottomAnimation.To = window.Top;
bottomAnimation.FillBehavior = FillBehavior.Stop;
bottomAnimation.Completed += (s, e) =>
{
window.Topmost = true;
// Set the final position again. This covers a case where frames are dropped.
// and the window ends up over the taskbar instead.
window.Top = top;
window.Activate();
window.Focus();
};
var easing = new QuinticEase();
easing.EasingMode = EasingMode.EaseOut;
bottomAnimation.EasingFunction = easing;
window.BeginAnimation(Window.TopProperty, bottomAnimation);
}
示例6: Animation_Opacity_View_Frame
public static void Animation_Opacity_View_Frame(this UIElement E, bool isview = true, Action CompleteAction = null, double minisecond=500)
{
Visibility visibility = E.Visibility;
if (visibility != Visibility.Visible)
{
E.Visibility = Visibility.Visible;
}
DoubleAnimation da = new DoubleAnimation() { Duration = TimeSpan.FromMilliseconds(minisecond), EasingFunction = new PowerEase() { Power = 4, EasingMode = EasingMode.EaseInOut } };
if (isview)
{
da.From = E.Opacity;
da.To = 1;
}
else
{
da.From = E.Opacity;
da.To = 0;
}
da.Completed += (o, e) =>
{
if (!isview)
E.Visibility = Visibility.Hidden;
if (CompleteAction != null)
{
CompleteAction();
}
};
E.BeginAnimation(UIElement.OpacityProperty, da);
}
示例7: AnimateOpacity
/// <summary>
/// Animates the opacity of the specified object.
/// </summary>
/// <param name="obj">
/// The object to animate.
/// </param>
/// <param name="targetOpacity">
/// The target opacity.
/// </param>
/// <param name="animationTime">
/// The animation time.
/// </param>
public static void AnimateOpacity(this IAnimatable obj, double targetOpacity, double animationTime)
{
var animation = new DoubleAnimation(targetOpacity, new Duration(TimeSpan.FromMilliseconds(animationTime)))
{
AccelerationRatio = 0.3,
DecelerationRatio = 0.5
};
obj.BeginAnimation(UIElement.OpacityProperty, animation);
}
示例8: AnimateTo
public static void AnimateTo(this RowDefinition row, double pixelValue, TimeSpan duration)
{
GridLengthAnimation heightAnim = new GridLengthAnimation() {
To = pixelValue,
Duration = new Duration(duration)
};
row.BeginAnimation(RowDefinition.HeightProperty, heightAnim);
}
示例9: Fade
/// <summary>Fades the specified source opacity.</summary>
/// <param name="control">The <c>control</c>.</param>
/// <param name="sourceOpacity">The source opacity.</param>
/// <param name="targetOpactity">The target <c>opactity</c>.</param>
/// <param name="milliseconds">The <c>milliseconds</c>.</param>
/// <exception cref="OverflowException"><paramref>
/// <name>value</name>
/// </paramref>
/// is less than <see cref="F:System.TimeSpan.MinValue" /> or greater than <see cref="F:System.TimeSpan.MaxValue" />.-or-<paramref>
/// <name>value</name>
/// </paramref>
/// is <see cref="F:System.Double.PositiveInfinity" />.-or-<paramref>
/// <name>value</name>
/// </paramref>
/// is <see cref="F:System.Double.NegativeInfinity" />. </exception>
public static void Fade(this UIElement control, double sourceOpacity, double targetOpactity, int milliseconds)
{
control.BeginAnimation(
UIElement.OpacityProperty,
new DoubleAnimation(
sourceOpacity,
targetOpactity,
new Duration(TimeSpan.FromMilliseconds(milliseconds))));
}
示例10: animateOpacity
public static void animateOpacity(this UIElement element, DependencyProperty prop, double from = 0, double to = 1)
{
double opa = element.Opacity;
if (opa == from)
{
DoubleAnimation op = new DoubleAnimation(from, to, program.tSpan);
element.BeginAnimation(prop, op);
}
if (to == 0) element.Visibility = Visibility.Hidden;
else element.Visibility = Visibility.Visible;
}
示例11: BeginDoubleAnimation
public static void BeginDoubleAnimation(this DependencyObject target, string path, double? to,
Duration duration)
{
var animation = new DoubleAnimation
{
To = to,
Duration = duration,
EnableDependentAnimation = true
};
target.BeginAnimation(animation, path);
}
示例12: AnimateSourceChange
/// <summary>
/// Provides an animation while changing the source of an <see cref="Image"/> control.
/// </summary>
/// <param name="image">The target <see cref="Image"/> control.</param>
/// <param name="source">The new <see cref="ImageSource"/> value.</param>
/// <param name="fadeOutDuration">The duration to run the fade out animation for.</param>
/// <param name="fadeInDuration">The duration to run the fade out animation for.</param>
public static void AnimateSourceChange(this Image image, ImageSource source, TimeSpan fadeOutDuration, TimeSpan fadeInDuration)
{
var fadeInAnimation = new DoubleAnimation(1d, fadeInDuration);
if (image.Source != null && fadeOutDuration > TimeSpan.Zero)
{
var fadeOutAnimation = new DoubleAnimation(0d, fadeOutDuration);
fadeOutAnimation.Completed += (o, e) =>
{
image.Source = source;
image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
};
image.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation);
}
else
{
image.Opacity = 0d;
image.Source = source;
image.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation);
}
}
示例13: ChangeSource
public static void ChangeSource(this Image image, ImageSource source, TimeSpan fadeOutTime, TimeSpan fadeInTime)
{
var fadeInAnimation = new DoubleAnimation(1d, fadeInTime);
if (image.Source != null)
{
var fadeOutAnimation = new DoubleAnimation(0d, fadeOutTime);
fadeOutAnimation.Completed += (o, e) =>
{
image.Source = source;
image.BeginAnimation(Image.OpacityProperty, fadeInAnimation);
};
image.BeginAnimation(Image.OpacityProperty, fadeOutAnimation);
}
else
{
image.Opacity = 0d;
image.Source = source;
image.BeginAnimation(Image.OpacityProperty, fadeInAnimation);
}
}
示例14: Animation_Color_Repeat
public static void Animation_Color_Repeat(this SolidColorBrush E, Color from, Color to, double time = 500)
{
if (from == null)
{
from = E.GetColor();
}
ColorAnimation animation = new ColorAnimation();
animation.From = from;
animation.To = to;
animation.Duration = TimeSpan.FromMilliseconds(time);
animation.RepeatBehavior = RepeatBehavior.Forever;
animation.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseInOut, Power = 3 };
E.BeginAnimation(SolidColorBrush.ColorProperty, animation);
}
示例15: FadeFromTo
public static UIElement FadeFromTo(this UIElement uiElement,
double fromOpacity, double toOpacity,
int durationInMilliseconds, bool loopAnimation, bool showOnStart, bool collapseOnFinish)
{
var timeSpan = TimeSpan.FromMilliseconds(durationInMilliseconds);
var doubleAnimation =
new DoubleAnimation(fromOpacity, toOpacity,
new Duration(timeSpan));
if (loopAnimation)
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
uiElement.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
if (showOnStart)
{
uiElement.ApplyAnimationClock(UIElement.VisibilityProperty, null);
uiElement.Visibility = Visibility.Visible;
}
if (collapseOnFinish)
{
var keyAnimation = new ObjectAnimationUsingKeyFrames { Duration = new Duration(timeSpan) };
keyAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(timeSpan)));
uiElement.BeginAnimation(UIElement.VisibilityProperty, keyAnimation);
}
return uiElement;
}