There is a circle that has events to move along the X axis behind the bounded coordinates.
If the circle is not brought to the end of one of the final coordinates - the condition if -> it moves to the end.
BUT! Because it happens abruptly. I decided to add the animation:
-
- <Storyboard x:Key="EllipseInite">
- <DoubleAnimation To="15" Duration="00:00:4">
- <DoubleAnimation.EasingFunction>
- <ElasticEase Oscillations="1"
- Springiness="27"
- EasingMode="EaseOut">
- </ElasticEase>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- </Storyboard>
-
- <Storyboard x:Key="EllipseFinite">
- <DoubleAnimation To="420" Duration="00:00:4" >
- <DoubleAnimation.EasingFunction>
- <ElasticEase Oscillations="1"
- Springiness="27"
- EasingMode="EaseOut">
- </ElasticEase>
- </DoubleAnimation.EasingFunction>
- </DoubleAnimation>
- </Storyboard>
The problem is that I can not understand why I can not or it is not called in Switcher (MainWindow) .xaml.cs?
- public partial class Switcher : Window
- {
- public Switcher()
- {
- InitializeComponent();
- }
-
- bool Action = false;
- double InitPxls = 15;
- double FinitePxls = 420;
- double Movement;
- Point Point;
-
- private void CircleKnob_MouseDown(object sender, MouseButtonEventArgs e)
- {
- Action = true;
- Point = Mouse.GetPosition(CircleKnob);
- Mouse.Capture(CircleKnob);
- }
-
- private void CircleKnob_MouseMove(object sender, MouseEventArgs e)
- {
- if (Action)
- {
- Movement = Canvas.GetLeft(CircleKnob) + Mouse.GetPosition(CircleKnob).X - Point.X;
-
- if (Movement > InitPxls && Movement < FinitePxls) {
- Canvas.SetLeft(CircleKnob, Movement);
- Canvas.SetLeft(CircleShadow, Movement - 15);
- }
- }
- }
-
- private void CircleKnob_MouseUp(object sender, MouseButtonEventArgs e)
- {
- Action = false;
- Mouse.Capture(null);
-
- if (Movement < InitPxls + 210)
- {
-
-
- this.Loaded += new RoutedEventHandler(InitAnimation);
- }
- else
- {
-
-
- this.Loaded += new RoutedEventHandler(FinitAnimation);
- }
- }
-
- private void InitAnimation(object sender, RoutedEventArgs e) {
- Storyboard Init = this.FindResource("EllipseInite" ) as Storyboard;
- Storyboard.SetTarget(Init, this.CircleKnob);
- Init.Begin();
- }
-
- private void FinitAnimation(object sender, RoutedEventArgs e)
- {
- Storyboard Init = this.FindResource("EllipseInite") as Storyboard;
- Storyboard.SetTarget(Init, this.CircleKnob);
- Init.Begin();
- }
- }
And here is the circle itself:
- <Ellipse x:Name="CircleKnob" Width="230" Height="230" Style="{StaticResource EllipseEffect}"
- Fill="{StaticResource Circle}"
- Canvas.Left="14" Canvas.Top="15"
-
- MouseDown="CircleKnob_MouseDown"
- MouseMove="CircleKnob_MouseMove"
- MouseUp ="CircleKnob_MouseUp" >
- </Ellipse>