2
延迟一个FadeInThemeAnimation我有一个包含在我的XAML中ProgressRing渐渐消逝进视图中的网格时,应用程序正在执行长时间运行的任务:XAML(Metro应用) - 如何通过第二
<Grid Height="100" Width="100" >
<Grid Background="#55000000" />
<ProgressRing x:Name="mapProgressRing" Width="50" Height="50" Foreground="White" />
</Grid>
</Border>
不过,我想1秒延迟动画的想法是,如果任务在不到结束第二,网格从不显示。因此,当执行非常短的任务时避免电网不断闪烁。
但是,尽管在上面的XAML中设置了BeginTime,但即使在代码中尝试此操作时,网格也会立即开始渐变到视图中。这里是我的代码:
void dataSou_WillStartFetchingSomething(object sender, EventArgs e)
{
// Don't bother fading in spinner unless it takes more than a second
showSpinner(TimeSpan.FromSeconds(1));
}
void Instance_WillEndFetchingSomething(object sender, EventArgs e)
{
hideSpinner();
}
#region Spinner
void showSpinner(TimeSpan? delayStartTime)
{
// Stop animation in case it's already running
mapRingFadeOutStoryBoard.Stop();
// Fade in, delaying the start by the specified time
mapRingFadeInStoryBoard.BeginTime = delayStartTime;
mapRingFadeInStoryBoard.Begin();
}
void hideSpinner()
{
// Stop the 'fade in' animation in case it's still running
mapRingFadeInStoryBoard.Stop();
// Fade out
mapRingFadeOutStoryBoard.Begin();
}
#endregion
我在做什么错?
这不会造成各种潜在的并发问题吗?例如如果showSpinner()被多次调用? – 2012-08-16 11:00:06
如果您想等待一秒钟,无论您在做什么,都会面临潜在的并发问题。除非你简单地停止主线程一秒钟,但是这样做的API幸运的是在WinRT中不可用,因为这只是不好的体验。这是一个勇敢的新世界,您需要了解如何处理并发问题。 :) – 2012-08-16 20:51:32
我曾想象过内置的Storyboard Begin,Stop等方法已经被设计为线程安全并且处理这些并发问题,你不觉得吗?在这种情况下,我只是说,因此尝试和处理那里的事情(如果可能)似乎是一种更好的方法,而不是重新发明轮子。 – 2012-08-17 11:35:11