本文整理汇总了C#中System.Windows.Media.TranslateTransform.BeginAnimation方法的典型用法代码示例。如果您正苦于以下问题:C# TranslateTransform.BeginAnimation方法的具体用法?C# TranslateTransform.BeginAnimation怎么用?C# TranslateTransform.BeginAnimation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.TranslateTransform
的用法示例。
在下文中一共展示了TranslateTransform.BeginAnimation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bounce
/// <summary>
/// Bounces the specified element.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="direction">The direction.</param>
/// <param name="whenDone">The when done.</param>
public static void Bounce(UIElement element, Direction direction, EventHandler whenDone = null)
{
var translateTransform = new TranslateTransform();
element.RenderTransform = translateTransform;
switch (direction)
{
case Direction.Up:
translateTransform.BeginAnimation(
TranslateTransform.YProperty,
CreateDoubleAnimation(
0,
-15,
0.2,
(o, e) => translateTransform.BeginAnimation(TranslateTransform.YProperty, CreateDoubleAnimationWithEasing(-15, 0, 0.8, new BounceEase { Bounces = 3, EasingMode = EasingMode.EaseOut })),
whenDone));
break;
case Direction.Down:
translateTransform.BeginAnimation(
TranslateTransform.YProperty,
CreateDoubleAnimation(
0,
15,
0.2,
(o, e) => translateTransform.BeginAnimation(TranslateTransform.YProperty, CreateDoubleAnimationWithEasing(15, 0, 0.8, new BounceEase { Bounces = 3, EasingMode = EasingMode.EaseOut })),
whenDone));
break;
}
}
示例2: 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);
}
示例3: ExpandMenu
private void ExpandMenu(Ellipse item, int distance)
{
DoubleAnimation animation = new DoubleAnimation(0, distance, TimeSpan.FromSeconds(.5));
TranslateTransform move = new TranslateTransform();
item.RenderTransform = move;
move.BeginAnimation(TranslateTransform.XProperty, animation);
move.BeginAnimation(TranslateTransform.YProperty, animation);
}
示例4: AnimateLayout
private void AnimateLayout()
{
var startDelay = new TimeSpan();
foreach (UIElement child in Children)
{
Point arrangePosition;
Transform currentTransform = GetCurrentLayoutInfo(child, out arrangePosition);
bool bypassTransform = _isAnimationValid != (int) GetValue(IsAnimationValidProperty);
// If we had previously stored an arrange position, see if it has moved
if (child.ReadLocalValue(SavedArrangePositionProperty) != DependencyProperty.UnsetValue)
{
var savedArrangePosition = (Point) child.GetValue(SavedArrangePositionProperty);
// If the arrange position hasn't changed, then we've already set up animations, etc
// and don't need to do anything
if (!AreClose(savedArrangePosition, arrangePosition))
{
// If we apply the current transform to the saved arrange position, we'll see where
// it was last rendered
Point lastRenderPosition = currentTransform.Transform(savedArrangePosition);
if (bypassTransform)
lastRenderPosition = (Point) child.GetValue(SavedCurrentPositionProperty);
else
child.SetValue(SavedCurrentPositionProperty, lastRenderPosition);
// Transform the child from the new location back to the old position
var newTransform = new TranslateTransform();
SetLayout2LayoutTransform(child, newTransform);
// Decay the transformation with an animation
double startValue = lastRenderPosition.X - arrangePosition.X;
newTransform.BeginAnimation(TranslateTransform.XProperty,
MakeStaticAnimation(startValue, startDelay));
newTransform.BeginAnimation(TranslateTransform.XProperty, MakeAnimation(startValue, startDelay),
HandoffBehavior.Compose);
startValue = lastRenderPosition.Y - arrangePosition.Y;
newTransform.BeginAnimation(TranslateTransform.YProperty,
MakeStaticAnimation(startValue, startDelay));
newTransform.BeginAnimation(TranslateTransform.YProperty, MakeAnimation(startValue, startDelay),
HandoffBehavior.Compose);
// Next element starts to move a little later
startDelay = startDelay.Add(CascadingDelay);
}
}
// Save off the previous arrange position
child.SetValue(SavedArrangePositionProperty, arrangePosition);
}
// currently WPF doesn't allow me to read a value right after the call to BeginAnimation
// this code enables me to trick it and know whether I can trust the current position or not.
_isAnimationValid = (int) GetValue(IsAnimationValidProperty) + 1;
BeginAnimation(IsAnimationValidProperty,
new Int32Animation(_isAnimationValid, _isAnimationValid, new Duration(), FillBehavior.HoldEnd));
}
示例5: AnimacjaRuchu
/// <summary>
/// Funkcja do animacji kropli wody
/// </summary>
/// <param name="target">Tutaj podajemy obiekt, który chcemy animować - w tym przypadku przesuwać wzdłuż osi X i Y</param>
/// <param name="animacjaDo">Iterator węzła od którego zaczynamy animacje</param>
/// <param name="animacjaOd">Iterator węzła do którego idzie animacja</param>
private void AnimacjaRuchu(Image target, int animacjaDo,int animacjaOd)
{
double newX = wezel[animacjaDo].X - wezel[animacjaOd].X;
double newY = wezel[animacjaDo].Y - wezel[animacjaOd].Y;
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(newX, TimeSpan.FromSeconds(2));
DoubleAnimation anim2 = new DoubleAnimation(newY, TimeSpan.FromSeconds(2));
trans.BeginAnimation(TranslateTransform.XProperty, anim1);
trans.BeginAnimation(TranslateTransform.YProperty, anim2);
}
示例6: MoveTo
public static void MoveTo(this Image target, double newX, double newY)
{
Vector offset = VisualTreeHelper.GetOffset(target);
var top = offset.Y;
var left = offset.X;
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(0, newY - top, TimeSpan.FromSeconds(10));
DoubleAnimation anim2 = new DoubleAnimation(0, newX - left, TimeSpan.FromSeconds(10));
trans.BeginAnimation(TranslateTransform.YProperty, anim1);
trans.BeginAnimation(TranslateTransform.XProperty, anim2);
}
示例7: PanelLayoutUpdated
/// <summary>
/// Called when panel's layout is updated
/// </summary>
/// <remarks>
/// Note: This is actually called when any layouts are updated
/// </remarks>
private void PanelLayoutUpdated(object sender, EventArgs e)
{
// At this point, the panel has moved the children to the new locations, but hasn't
// been rendered
foreach (UIElement child in _panel.Children)
{
// Figure out where child actually is right now. This is a combination of where the
// panel put it and any render transform currently applied
Point currentPosition = child.TransformToAncestor(_panel).Transform(new Point());
// See what transform is being applied
Transform currentTransform = child.RenderTransform;
// Compute where the panel actually arranged it to
Point arrangePosition = currentPosition;
if (currentTransform != null)
{
// Undo any transform we applied
arrangePosition = currentTransform.Inverse.Transform(arrangePosition);
}
// If we had previously stored an arrange position, see if it has moved
if (child.ReadLocalValue(SavedArrangePositionProperty) != DependencyProperty.UnsetValue)
{
Point savedArrangePosition = (Point)child.GetValue(SavedArrangePositionProperty);
// If the arrange position hasn't changed, then we've already set up animations, etc
// and don't need to do anything
if (!AreReallyClose(savedArrangePosition, arrangePosition))
{
// If we apply the current transform to the saved arrange position, we'll see where
// it was last rendered
Point lastRenderPosition = currentTransform.Transform(savedArrangePosition);
// Transform the child from the new location back to the old position
TranslateTransform newTransform = new TranslateTransform();
child.RenderTransform = newTransform;
// Decay the transformation with an animation
newTransform.BeginAnimation(TranslateTransform.XProperty, MakeAnimation(lastRenderPosition.X - arrangePosition.X));
newTransform.BeginAnimation(TranslateTransform.YProperty, MakeAnimation(lastRenderPosition.Y - arrangePosition.Y));
}
}
// Save off the previous arrange position
child.SetValue(SavedArrangePositionProperty, arrangePosition);
}
}
示例8: LoadClick
public void LoadClick(object sender, EventArgs e)
{
//MarkAllUiElementsWithTags(); //to delete it later
var but = sender as Button;
var move = new TranslateTransform(0, 0);
var anim = new DoubleAnimation()
{
Duration = new Duration(TimeSpan.FromSeconds(0.7)),
To = but.Margin.Left + Load.Width + 5,
AccelerationRatio = 0.5,
};
anim.Completed += MoveToLoad;
but.RenderTransform = move;
move.BeginAnimation(TranslateTransform.XProperty, anim);
var moveOther = new TranslateTransform(0, 0);
var animOther = new DoubleAnimation()
{
Duration = new Duration(TimeSpan.FromSeconds(0.5)),
To = -Create.Width - 5,
AccelerationRatio = 0.5,
};
Create.RenderTransform = moveOther;
moveOther.BeginAnimation(TranslateTransform.XProperty, animOther);
}
示例9: MoveCharacterPan
public static void MoveCharacterPan(TranslateTransform transform, DependencyProperty propertyToPan, Double toValue)
{
if (transform != null)
{
UiThread.Execute(() =>
transform.BeginAnimation(propertyToPan, GetMoveCharacterPanAnimation(toValue), HandoffBehavior.SnapshotAndReplace));
}
}
示例10: BeginTransition
protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
{
TranslateTransform tt = new TranslateTransform(StartPoint.X * transitionElement.ActualWidth, StartPoint.Y * transitionElement.ActualHeight);
if (IsNewContentTopmost)
newContent.RenderTransform = tt;
else
oldContent.RenderTransform = tt;
DoubleAnimation da = new DoubleAnimation(EndPoint.X * transitionElement.ActualWidth, Duration);
tt.BeginAnimation(TranslateTransform.XProperty, da);
da.To = EndPoint.Y * transitionElement.ActualHeight;
da.Completed += delegate {
EndTransition(transitionElement, oldContent, newContent);
};
tt.BeginAnimation(TranslateTransform.YProperty, da);
}
示例11: ConfirmationLocalModalInteractionDialog_Loaded
void ConfirmationLocalModalInteractionDialog_Loaded(object sender, RoutedEventArgs e)
{
DoubleAnimation doubleAnim = new DoubleAnimation(-460, 0,
new Duration(new TimeSpan(0, 0, 0, 0, 200)));
var trans = new TranslateTransform();
this.RenderTransform = trans;
trans.BeginAnimation(TranslateTransform.XProperty, doubleAnim);
}
示例12: decreaseDigit
private void decreaseDigit(TranslateTransform tf, TimeSpan time)
{
double newPos = tf.Y;
newPos = newPos + resolutionPerNumber;
DoubleAnimation animationTB1 = new DoubleAnimation(newPos, time);
tf.BeginAnimation(TranslateTransform.YProperty, animationTB1);
}
示例13: Grow
public void Grow()
{
BringIntoView();
const int mult = 10;
const double duration = 0.1;
RenderTransform = new TranslateTransform();
var translateAnimation = new DoubleAnimation { From = 0, To = (-Width * mult / 2), Duration = TimeSpan.FromSeconds(duration), AutoReverse = true };
RenderTransform.BeginAnimation(TranslateTransform.XProperty, translateAnimation);
RenderTransform.BeginAnimation(TranslateTransform.YProperty, translateAnimation);
Ellipse.RenderTransform = new ScaleTransform();
var scaleAnimation = new DoubleAnimation { From = 1, To = mult, Duration = TimeSpan.FromSeconds(duration), AutoReverse = true };
Ellipse.RenderTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
Ellipse.RenderTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
//(RadialGradientBrush)FindResource("RedGradient")
//var colorTransform = new ColorAnimation {To = Colors.Red, Duration=TimeSpan.FromSeconds(0.1), AutoReverse= true};
//var brush = (RadialGradientBrush)FindResource("RedGradient");
//brush.BeginAnimation();
}
示例14: BeginAnimateContentReplacement
/// <summary>
/// Starts the animation for the new content
/// </summary>
private void BeginAnimateContentReplacement()
{
var newContentTransform = new TranslateTransform();
var oldContentTransform = new TranslateTransform();
m_paintArea.RenderTransform = oldContentTransform;
m_mainContent.RenderTransform = newContentTransform;
m_paintArea.Visibility = Visibility.Visible;
newContentTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(this.ActualWidth, 0));
oldContentTransform.BeginAnimation(TranslateTransform.XProperty, CreateAnimation(0, -this.ActualWidth, (s, e) => m_paintArea.Visibility = Visibility.Hidden));
}
示例15: AnimateFirstBull
private void AnimateFirstBull()
{
DoubleAnimation translate = new DoubleAnimation();
translate.From = 0;
translate.To = 110;
translate.AutoReverse = false;
translate.Duration = new Duration(TimeSpan.FromSeconds(1.300));
TranslateTransform tt = new TranslateTransform();
bull.RenderTransform = tt;
tt.BeginAnimation(TranslateTransform.YProperty, translate);
}