TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Alexandr Laketych
NA
17
1.3k
How to call Storyboard in .xaml.cs ?
Jun 16 2018 12:50 AM
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:
<!--ANIMATED ELLIPSE TO CORNERS-->
<
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)
{
//Canvas.SetLeft(CircleKnob, InitPxls);
//Canvas.SetLeft(CircleShadow, InitPxls - 15);
this
.Loaded +=
new
RoutedEventHandler(InitAnimation);
}
else
{
//Canvas.SetLeft(CircleKnob, InitPxls);
//Canvas.SetLeft(CircleShadow, InitPxls - 15);
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
>
Reply
Answers (
1
)
Resizing and setting Events for WMPLib.WindowsMediaPlayer
No motion animation of objects