Ich habe Kontrolle mit Animation, die Bild dreht.Pause Drehanimation in WPF
Ich möchte die Rotationsanimation jederzeit starten, anhalten und fortsetzen.
Ich habe alles hinter Code:
public partial class Wheel32Control : UserControl
{
public Wheel32Control()
{
InitializeComponent();
img.RenderTransform = new RotateTransform();
img.RenderTransformOrigin = new Point(0.5, 0.5);
_daRotate = new DoubleAnimation(0, 360, TimeSpan.FromSeconds(2))
{
RepeatBehavior = RepeatBehavior.Forever
};
}
private DoubleAnimation _daRotate;
private bool _rotate;
public bool Rotate
{
get
{
return _rotate;
}
set
{
_rotate = value;
if (_rotate)
RotateStart();
else
RotateStop();
}
}
private void RotateStart()
{
this.img.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, _daRotate);
}
private void RotateStop()
{
this.img.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, null);
}
}
Meine XAML Teil:
<Image Name="img" Source="/Plt;component/Resources/Images/Kolo_32_3.png"
Stretch="None"/>
Mein Problem:
Wenn ich Animation stoppen - es "springt" auf "Nullpunkt" . Ich möchte, dass es aufhört, wo es war, als ich es beendete.
Mein Code setzt die Animation auf "null", weil ich neu in WPF bin und dies ist nur eine Möglichkeit, die Animation zu stoppen, die ich kenne.
Schöne und saubere Lösung . Danke, dass du eine Erklärung für "seltsames Teil" hinzugefügt hast! – Kamil