本文整理汇总了C#中Windows.UI.Xaml.Media.Animation.Storyboard.BeginAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Storyboard.BeginAsync方法的具体用法?C# Storyboard.BeginAsync怎么用?C# Storyboard.BeginAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.Media.Animation.Storyboard
的用法示例。
在下文中一共展示了Storyboard.BeginAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FadeOut
/// <summary>
/// Fades the element out using the FadeOutThemeAnimation.
/// </summary>
/// <remarks>
/// Opacity property of the element is not affected.<br/>
/// The duration of the visible animation itself is not affected by the duration parameter. It merely indicates how long the Storyboard will run.<br/>
/// If FadeOutThemeAnimation was already run before and FadeInThemeAnimation was not run after that - nothing will happen.<br/>
/// </remarks>
/// <param name="dob"></param>
/// <param name="duration"></param>
/// <returns></returns>
public static async Task FadeOut(this DependencyObject dob, TimeSpan? duration = null)
{
var fadeOutStoryboard = new Storyboard();
var fadeOutAnimation = new FadeOutThemeAnimation();
if (duration != null)
{
fadeOutAnimation.Duration = duration.Value;
}
Storyboard.SetTarget(fadeOutAnimation, dob);
fadeOutStoryboard.Children.Add(fadeOutAnimation);
await fadeOutStoryboard.BeginAsync();
}
示例2: FadeIn
/// <summary>
/// Fades the element in using the FadeInThemeAnimation.
/// </summary>
/// <remarks>
/// Opacity property of the element is not affected.<br/>
/// The duration of the visible animation itself is not affected by the duration parameter. It merely indicates how long the Storyboard will run.<br/>
/// If FadeOutThemeAnimation was not used on the element before - nothing will happen.<br/>
/// </remarks>
/// <param name="dob"></param>
/// <param name="duration"></param>
/// <returns></returns>
public static async Task FadeIn(this DependencyObject dob, TimeSpan? duration = null)
{
((FrameworkElement)dob).Visibility = Visibility.Visible;
var fadeInStoryboard = new Storyboard();
var fadeInAnimation = new FadeInThemeAnimation();
if (duration != null)
{
fadeInAnimation.Duration = duration.Value;
}
Storyboard.SetTarget(fadeInAnimation, dob);
fadeInStoryboard.Children.Add(fadeInAnimation);
await fadeInStoryboard.BeginAsync();
}
示例3: AnimateOpacityToAsync
/// <summary>
/// Animates the opacity of an element
/// </summary>
/// <param name="element">The element to animate</param>
/// <param name="finalOpacity">Final Opacity</param>
/// <param name="durationInSeconds">Duration in seconds</param>
/// <param name="OnComplete">[Optional] Action to perform on complete</param>
/// <returns>Storyboard created</returns>
public static async Task<Storyboard> AnimateOpacityToAsync(this FrameworkElement element, double finalOpacity,
double durationInSeconds, Action OnComplete = null)
{
ValidateForNull(element);
ValidateCompositeTransform(element);
if (element.RenderTransform == null) element.RenderTransform = new CompositeTransform();
Storyboard sb = new Storyboard();
DoubleAnimation opacityAnimation = CreateDoubleAnimation(element,
durationInSeconds, finalOpacity,
"(FrameworkElement.Opacity)");
sb.Children.Add(opacityAnimation);
await sb.BeginAsync();
return sb;
}
示例4: FadeInCustom
/// <summary>
/// Fades the element in using a custom DoubleAnimation of the Opacity property.
/// </summary>
/// <param name="dob"></param>
/// <param name="duration"></param>
/// <param name="easingFunction"> </param>
/// <returns></returns>
public static async Task FadeInCustom(this DependencyObject dob, TimeSpan? duration = null, EasingFunctionBase easingFunction = null)
{
var fadeInStoryboard = new Storyboard();
var fadeInAnimation = new DoubleAnimation();
if (duration == null)
duration = TimeSpan.FromSeconds(0.4);
fadeInAnimation.Duration = duration.Value;
fadeInAnimation.To = 1.0;
fadeInAnimation.EasingFunction = easingFunction;
Storyboard.SetTarget(fadeInAnimation, dob);
Storyboard.SetTargetProperty(fadeInAnimation, "Opacity");
fadeInStoryboard.Children.Add(fadeInAnimation);
await fadeInStoryboard.BeginAsync();
}
示例5: Animate
private async Task Animate()
{
var sb = new Storyboard();
var daX = new DoubleAnimation();
var daY = new DoubleAnimation();
daX.Duration = TimeSpan.FromSeconds(0.8);
daY.Duration = TimeSpan.FromSeconds(0.8);
Storyboard.SetTarget(daX, AnimatedTransform);
Storyboard.SetTarget(daY, AnimatedTransform);
Storyboard.SetTargetProperty(daX, "X");
Storyboard.SetTargetProperty(daY, "Y");
daX.To = rand.Next(0, (int)AnimationPanel.ActualWidth - 100);
daY.To = rand.Next(0, (int)AnimationPanel.ActualHeight - 100);
sb.Children.Add(daX);
sb.Children.Add(daY);
await sb.BeginAsync();
}
示例6: AnimateToStraightenAsync
private async Task AnimateToStraightenAsync()
{
if (_layoutGridTransform == null)
{
return;
}
var sb = new Storyboard();
var dar = new DoubleAnimation();
dar.Duration = TimeSpan.FromSeconds(.2);
Storyboard.SetTarget(dar, _layoutGridTransform);
Storyboard.SetTargetProperty(dar, "Rotation");
dar.To = 0;
sb.Children.Add(dar);
if (_titleTransform != null &&
_titleGrid != null &&
_titleTransform.Rotation == -180)
{
var dato = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(dato, _titleGrid);
Storyboard.SetTargetProperty(dato, "Opacity");
dato.KeyFrames.Add(new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(0), Value = 1 });
dato.KeyFrames.Add(new LinearDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(.1), Value = 0 });
dato.KeyFrames.Add(new LinearDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(.2), Value = 1 });
sb.Children.Add(dato);
var datr = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(datr, _titleTransform);
Storyboard.SetTargetProperty(datr, "Rotation");
datr.KeyFrames.Add(new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(.1), Value = 0 });
sb.Children.Add(datr);
var datt = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(datt, _titleTransform);
Storyboard.SetTargetProperty(datt, "TranslateY");
datt.KeyFrames.Add(new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(.1), Value = 0 });
sb.Children.Add(datt);
}
await sb.BeginAsync();
CleanupSnapProperties();
}
示例7: OnBorderTapped
//.........这里部分代码省略.........
(0.25 + 0.75 * Math.Min(hsv.L, hsv.S));
var actualPosition =
child.TransformToVisual(grid)
.TransformPoint(new Point(0, 0));
//Debug.WriteLine(actualPosition);
var deltaX = targetX - actualPosition.X;
var deltaY = targetY - actualPosition.Y;
var xa = new DoubleAnimation();
xa.BeginTime = beginTime;
xa.Duration = TimeSpan.FromSeconds(1);
xa.To = deltaX;
Storyboard.SetTarget(xa, child.RenderTransform);
Storyboard.SetTargetProperty(xa, "TranslateX");
sb1.Children.Add(xa);
var ya = new DoubleAnimation();
ya.BeginTime = beginTime;
ya.Duration = TimeSpan.FromSeconds(1);
ya.To = deltaY;
Storyboard.SetTarget(ya, child.RenderTransform);
Storyboard.SetTargetProperty(ya, "TranslateY");
sb1.Children.Add(ya);
var aa = new DoubleAnimation();
aa.BeginTime = beginTime;
aa.Duration = TimeSpan.FromSeconds(1);
aa.To = hsv.H;
Storyboard.SetTarget(aa, child.RenderTransform);
Storyboard.SetTargetProperty(aa, "Rotation");
sb1.Children.Add(aa);
}
await sb1.BeginAsync();
}
if (currentCall != _onBorderTappedCall)
{
return;
}
const double revolutionDurationInS = 30d;
foreach (var child in grid.Children)
{
child.RenderTransform = new CompositeTransform();
child.RenderTransformOrigin = new Point(0.5, 0.5);
var nc = (NamedColor)((FrameworkElement)child).DataContext;
var hsv = nc.Color.ToHsl();
var actualPosition = child.TransformToVisual(grid).TransformPoint(new Point(0, 0));
var sb = new Storyboard();
sb.RepeatBehavior = RepeatBehavior.Forever;
var minX = center.X - center.X * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.X;
var midX = center.X - actualPosition.X;
var maxX = center.X + center.X * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.X;
var minY = center.Y - center.Y * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.Y;
var midY = center.Y - actualPosition.Y;
var maxY = center.Y + center.Y * (0.25 + 0.75 * Math.Min(hsv.L, hsv.S)) - actualPosition.Y;
var xa = new DoubleAnimationUsingKeyFrames();
xa.KeyFrames.Add(new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = midX});
xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.25), Value = maxX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.50), Value = midX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseIn } });
xa.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(revolutionDurationInS * 0.75), Value = minX, EasingFunction = new SineEase { EasingMode = EasingMode.EaseOut } });
示例8: ScrollToVerticalOffsetWithAnimation
internal async Task ScrollToVerticalOffsetWithAnimation(
double offset,
TimeSpan duration,
EasingFunctionBase easingFunction)
{
var sb = new Storyboard();
var da = new DoubleAnimation();
da.EnableDependentAnimation = true;
da.From = _scrollViewer.VerticalOffset;
da.To = offset;
da.EasingFunction = easingFunction;
da.Duration = duration;
sb.Children.Add(da);
Storyboard.SetTarget(sb, _sliderVertical);
Storyboard.SetTargetProperty(da, "Value");
await sb.BeginAsync();
}
示例9: ZoomToFactorWithAnimationAsync
internal async Task ZoomToFactorWithAnimationAsync(
double factor,
TimeSpan duration,
EasingFunctionBase easingFunction)
{
var sb = new Storyboard();
var da = new DoubleAnimation
{
EnableDependentAnimation = true,
From = this._scrollViewer.ZoomFactor,
To = factor,
EasingFunction = easingFunction,
Duration = duration
};
sb.Children.Add(da);
Storyboard.SetTarget(sb, this._sliderZoom);
Storyboard.SetTargetProperty(da, "Value");
await sb.BeginAsync();
}
示例10: ScrollToHorizontalOffsetWithAnimationAsync
internal async Task ScrollToHorizontalOffsetWithAnimationAsync(
double offset,
TimeSpan duration,
EasingFunctionBase easingFunction)
{
var sb = new Storyboard();
var da = new DoubleAnimation
{
EnableDependentAnimation = true,
From = this._scrollViewer.HorizontalOffset,
To = offset,
EasingFunction = easingFunction,
Duration = duration
};
sb.Children.Add(da);
Storyboard.SetTarget(sb, this._sliderHorizontal);
Storyboard.SetTargetProperty(da, "Value");
await sb.BeginAsync();
}
示例11: FadeOutAsync
/// <summary>
/// Fades the element out using the FadeOutThemeAnimation.
/// </summary>
/// <remarks>
/// Opacity property of the element is not affected.<br/>
/// The duration of the visible animation itself is not affected by the duration parameter. It merely indicates how long the Storyboard will run.<br/>
/// If FadeOutThemeAnimation was already run before and FadeInThemeAnimation was not run after that - nothing will happen.<br/>
/// </remarks>
/// <param name="element"></param>
/// <param name="duration"></param>
/// <returns></returns>
public static async Task FadeOutAsync(this UIElement element, TimeSpan? duration = null)
{
var fadeOutStoryboard = new Storyboard();
var fadeOutAnimation = new FadeOutThemeAnimation();
if (duration != null)
{
fadeOutAnimation.Duration = duration.Value;
}
Storyboard.SetTarget(fadeOutAnimation, element);
fadeOutStoryboard.Children.Add(fadeOutAnimation);
await fadeOutStoryboard.BeginAsync();
}
示例12: RotateByAsync
/// <summary>
/// Rotates an element by relative angles
/// </summary>
/// <param name="element">Element to rotate</param>
/// <param name="deltaAngles">Relative angles rotation</param>
/// <param name="durationInSeconds">Duration in seconds</param>
/// <param name="OnComplete">[Optional] Action to perform on complete</param>
/// <returns>Storyboard created</returns>
public static async Task<Storyboard> RotateByAsync(this FrameworkElement element, double deltaAngles,
double durationInSeconds, Action OnComplete = null)
{
ValidateForNull(element);
ValidateCompositeTransform(element);
Storyboard sb = new Storyboard();
DoubleAnimation rotationAnimation = CreateDoubleAnimation(element,
durationInSeconds, deltaAngles + (element.RenderTransform as CompositeTransform).Rotation,
"(FrameworkElement.RenderTransform).(CompositeTransform.Rotation)");
sb.Children.Add(rotationAnimation);
await sb.BeginAsync();
if (OnComplete != null) OnComplete();
return sb;
}
示例13: BeginCascadingTransitionAsync
//.........这里部分代码省略.........
KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration + CascadeOutDuration,
EasingFunction = CascadeOutEasingFunction,
Value = ToRotation
});
}
}
if (CascadeIn)
{
yAnimation.KeyFrames.Add(
new DiscreteDoubleKeyFrame
{
KeyTime = totalDelay,
Value = FromVerticalOffset
});
yAnimation.KeyFrames.Add(
new EasingDoubleKeyFrame
{
KeyTime = totalDelay + CascadeInDuration,
EasingFunction = CascadeInEasingFunction,
Value = 0
});
if (UseFade)
{
opacityAnimation.KeyFrames.Add(
new DiscreteDoubleKeyFrame
{
KeyTime = totalDelay,
Value = 0
});
opacityAnimation.KeyFrames.Add(
new EasingDoubleKeyFrame
{
KeyTime = totalDelay + CascadeInDuration,
EasingFunction = FadeInEasingFunction,
Value = 1.0
});
}
}
if (CascadeOut)
{
yAnimation.KeyFrames.Add(
new DiscreteDoubleKeyFrame
{
KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration,
Value = 0
});
yAnimation.KeyFrames.Add(
new EasingDoubleKeyFrame
{
KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration + CascadeOutDuration,
EasingFunction = CascadeOutEasingFunction,
Value = ToVerticalOffset
});
if (UseFade)
{
opacityAnimation.KeyFrames.Add(
new DiscreteDoubleKeyFrame
{
KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration,
Value = 1.00
});
opacityAnimation.KeyFrames.Add(
new EasingDoubleKeyFrame
{
KeyTime = totalDelay + (CascadeIn ? CascadeInDuration : TimeSpan.Zero) + HoldDuration + CascadeOutDuration,
EasingFunction = FadeOutEasingFunction,
Value = 0.0
});
}
}
totalDelay += CascadeInterval;
i += j;
}
EventHandler<object> eh = null;
eh = (s, e) =>
{
cascadeStoryboard.Completed -= eh;
//LayoutRoot.Children.Clear();
//var tb2 = CreateTextBlock(null);
//tb2.Text = Text;
//LayoutRoot.Children.Add(tb2);
#if CascadingTextBlock_REPEATFOREVER
BeginCascadingTransition();
#else
if (CascadeCompleted != null)
CascadeCompleted(this, EventArgs.Empty);
#endif
};
cascadeStoryboard.Completed += eh;
await Task.Delay(StartDelay);
await cascadeStoryboard.BeginAsync();
}
示例14: StartCountdownAsync
/// <summary>
/// Starts the countdown and completes when the countdown completes.
/// </summary>
/// <param name="seconds">The seconds.</param>
/// <returns></returns>
public async Task StartCountdownAsync(int seconds)
{
_countingDown = true;
this.Seconds = seconds;
bool grow = true;
while (this.Seconds > 0)
{
var sb = new Storyboard();
if (grow)
{
////Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "grow");
var da = new DoubleAnimation
{
From = 0d,
To = 359.999d,
Duration = new Duration(TimeSpan.FromSeconds(1d)),
EnableDependentAnimation = true
};
sb.Children.Add(da);
sb.RepeatBehavior = new RepeatBehavior(1);
// Workaround for a problem animating custom dependency properties
//PART_RingSlice.SetBinding(
// RingSlice.EndAngleProperty,
// new Binding { Source = r1, Path = new PropertyPath("Opacity"), Mode = BindingMode.OneWay });
//Storyboard.SetTargetProperty(da, "Opacity");
//Storyboard.SetTarget(sb, r1);
Storyboard.SetTargetProperty(da, "EndAngle");
Storyboard.SetTarget(sb, PART_RingSlice);
}
else
{
////Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "shrink");
var da = new DoubleAnimation
{
From = 0d,
To = 359.999d,
Duration = new Duration(TimeSpan.FromSeconds(1d)),
EnableDependentAnimation = true
};
sb.Children.Add(da);
sb.RepeatBehavior = new RepeatBehavior(1);
//PART_RingSlice.SetBinding(
// RingSlice.StartAngleProperty,
// new Binding { Source = r2, Path = new PropertyPath("Opacity"), Mode = BindingMode.OneWay });
//Storyboard.SetTargetProperty(da, "Opacity");
//Storyboard.SetTarget(sb, r2);
Storyboard.SetTargetProperty(da, "StartAngle");
Storyboard.SetTarget(sb, PART_RingSlice);
}
PART_Label.Text = this.Seconds.ToString();
////Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "before animation");
await sb.BeginAsync();
////Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "after animation");
if (grow)
{
PART_RingSlice.StartAngle = 0d;
PART_RingSlice.EndAngle = 359.999d;
}
else
{
PART_RingSlice.StartAngle = 0d;
PART_RingSlice.EndAngle = 0d;
}
grow = !grow;
this.Seconds--;
}
PART_Label.Text = this.Seconds.ToString();
if (this.CountdownComplete != null)
{
////Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "before countdowncomplete");
CountdownComplete(this, new RoutedEventArgs());
////Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "after countdowncomplete");
}
_countingDown = false;
}
示例15: BeginSleepStoryboardAsync
/// <summary>
/// Simulates a thread sleep
/// </summary>
/// <param name="durationInSeconds">Duration in seconds</param>
/// <returns>Storyboard created</returns>
public async static Task<Storyboard> BeginSleepStoryboardAsync(double durationInSeconds)
{
Storyboard sb = new Storyboard();
sb.Duration = TimeSpan.FromSeconds(durationInSeconds);
await sb.BeginAsync();
return sb;
}