做一个wpf的电子地图,在图上有闪烁的红点表示特定区域,实验代码如下:
xaml代码:
<
Storyboard
x:Key
="Storyboard1"
RepeatBehavior
="Forever"
AutoReverse
="True"
>
< DoubleAnimationUsingKeyFrames BeginTime ="00:00:00" Storyboard.TargetName ="ellipse1" Storyboard.TargetProperty ="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" >
< SplineDoubleKeyFrame KeyTime ="00:00:00" Value ="1" />
< SplineDoubleKeyFrame KeyTime ="00:00:01" Value ="2" />
</ DoubleAnimationUsingKeyFrames >
< DoubleAnimationUsingKeyFrames BeginTime ="00:00:00" Storyboard.TargetName ="ellipse1" Storyboard.TargetProperty ="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" >
< SplineDoubleKeyFrame KeyTime ="00:00:00" Value ="1" />
< SplineDoubleKeyFrame KeyTime ="00:00:01" Value ="2" />
</ DoubleAnimationUsingKeyFrames >
</ Storyboard >
< DoubleAnimationUsingKeyFrames BeginTime ="00:00:00" Storyboard.TargetName ="ellipse1" Storyboard.TargetProperty ="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" >
< SplineDoubleKeyFrame KeyTime ="00:00:00" Value ="1" />
< SplineDoubleKeyFrame KeyTime ="00:00:01" Value ="2" />
</ DoubleAnimationUsingKeyFrames >
< DoubleAnimationUsingKeyFrames BeginTime ="00:00:00" Storyboard.TargetName ="ellipse1" Storyboard.TargetProperty ="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" >
< SplineDoubleKeyFrame KeyTime ="00:00:00" Value ="1" />
< SplineDoubleKeyFrame KeyTime ="00:00:01" Value ="2" />
</ DoubleAnimationUsingKeyFrames >
</ Storyboard >
后台控制代码如下:
my_sb
=
(Storyboard)
this
.FindResource(
"
Storyboard1
"
);
my_sb.Begin( this );
my_sb.Begin( this );
这个Storyboard的RepeatBehavior="Forever"
现在想做一个控制,让Storyboard可以恢复原状:
首先使用如下代码:
my_sb
=
(Storyboard)
this
.FindResource(
"
Storyboard1
"
);
my_sb.Stop( this );
my_sb.Stop( this );
接下来要做一个按钮,能暂停和继续Storyboard,代码如下:
my_sb
=
(Storyboard)
this
.FindResource(
"
Storyboard1
"
);
bool state = my_sb.GetIsPaused( this );
if ( ! state)
{
my_sb.Pause( this );
}
if (state)
my_sb.Resume( this );
bool state = my_sb.GetIsPaused( this );
if ( ! state)
{
my_sb.Pause( this );
}
if (state)
my_sb.Resume( this );
上述代码中my_sb.GetIsPaused(this)判断storyboard当前是不是暂停状态
接下来还要做一个按钮,能停止和启动Storyboard,但是Storyboard没有函数判断Storyboard是否运行状态。应该还要利用clock状态
明天继续做实验。