c# - XAML(Metro 应用程序)- 如何将 FadeInThemeAnimation 延迟一秒

标签 c# xaml windows-runtime winrt-xaml

我的 XAML 中有一个包含 ProgressRing 的网格,当应用程序执行长时间运行的任务时,它会淡入 View :

        <Grid Height="100" Width="100"  >
            <Grid Background="#55000000" />
            <ProgressRing x:Name="mapProgressRing"  Width="50" Height="50" Foreground="White" />    
        </Grid>
        </Border>

但是,我想将动画延迟 1 秒,其想法是如果任务在不到一秒内完成,则永远不会显示网格。从而避免在执行非常短的任务时网格不断闪烁。

但是,尽管在上面的 XAML 中设置了 BeginTime,网格总是立即开始淡入 View ,即使我在代码中尝试这样做也是如此。这是我的代码:

    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

我做错了什么?

最佳答案

不确定哪里出了问题,但您可以改用 async/await。只需将您的方法标记为异步,然后执行“await Task.Delay(1000)”以在开始动画之前等待一秒钟。

关于c# - XAML(Metro 应用程序)- 如何将 FadeInThemeAnimation 延迟一秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11950255/

相关文章:

c# - 从网络爬虫中提取内容时,哪些解决方案更快

c# - 如何提高加载大量记录到 WPF 下拉列表的性能?

c# - 在 WPF 中,DependencyProperty 在与值类型一起使用时会导致大量装箱/拆箱吗?

c# - Silverlight:来自一个用户控件的事件能否在不同的用户控件和/或包含控件上开始动画

c# - 测试以确保用户输入是 double 且大于零?

wpf - 不同触发器的相同 setter

c# - Wpf 列表框比窗口大

c# - Storyboard DoubleAnimation 不适用于 StackPanel 高度属性

c# - 用sqlite和winrt编译报错

c# - 静态构造函数之前的异步加载设置