请教有关StoryBoard的问题

weixin_38067167 2017-10-25 06:46:44
我在窗体中做了一个loading的图标:
<Path Name="LoadingIcon2" Stroke="#888" Visibility="Collapsed" StrokeThickness="3" Width="24" Height="24" RenderTransformOrigin="0.5,0.5" Panel.ZIndex="100" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="6 0 0 6">
<Path.RenderTransform>
<RotateTransform Angle="0"></RotateTransform>
</Path.RenderTransform>
<Path.Data>
<GeometryGroup>
<PathGeometry Figures="M 12,2 A 10,10 0 1 0 22,12"></PathGeometry>
</GeometryGroup>
</Path.Data>
</Path>


然后通过代码去显示,并且让其旋转:
private void ShowLoading()
{
LoadingIcon2.Visibility = Visibility.Visible;
LoadingIcon2.Opacity = 1;
DoubleAnimation ani = new DoubleAnimation(0, 360, TimeSpan.FromMilliseconds(1000));
Storyboard st = new Storyboard();
Storyboard.SetTarget(ani, LoadingIcon2);
Storyboard.SetTargetProperty(ani, new PropertyPath("RenderTransform.Angle"));
st.RepeatBehavior = RepeatBehavior.Forever;
st.Children.Add(ani);
st.Begin();
}
private void CloseLoading()
{
DoubleAnimation ani = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(500));
ani.EasingFunction = new CubicEase();
Storyboard st = new Storyboard();
Storyboard.SetTarget(ani, LoadingIcon2);
Storyboard.SetTargetProperty(ani, new PropertyPath("Opacity"));
st.Children.Add(ani);
st.Completed += (o, evt) =>
{
LoadingIcon2.Visibility = Visibility.Collapsed;
};
st.Begin();
}


showLoading方法可以让那个图标产生旋转效果;
然后调用CloseLoading方法,可以将图标淡出并最终隐藏起来;
当我按照:showLoading - CloseLoading的顺序去调用的时候,产生的效果正如我预想中的那样;
可是,当我Close了之后再Show的时候,却发现图标不显示了。我明明在Show方法那里强制将Opacity设置为1的,可是通过“实时可视化树”查看对象属性,却发现Opacity为零,这是为什么?


da jia hao!
...全文
13 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧