Splash window 没有关闭 - WPF

Splash window doesn't close - WPF

我有一个带有进度条的启动画面,一旦它完全加载,主 window 应该打开。然而主 window 根本打不开,启动画面 window 即使在进度条完全加载后仍然存在。怎么了?

在App.xaml中,我设置了StartupUri="SplashWindow.xaml"

飞溅Window代码:

using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;
using System.Windows.Media.Animation;

namespace Project_1
{
/// <summary>
/// Interaction logic for SplashWindow.xaml
/// </summary>
public partial class SplashWindow : Window
{
    public SplashWindow()
    {
        this.InitializeComponent();


       Duration duration = new Duration(System.TimeSpan.FromSeconds(10));
       DoubleAnimation doubleanimation = new     DoubleAnimation(splash_load.Maximum, duration);
       splash_load.BeginAnimation(ProgressBar.ValueProperty, doubleanimation); 

        if (splash_load.Value==100) //If progress bar (Name = "splash_load") loads completely
        {

        // Close splash window
        this.Close();

        // Open main window
        var mw = new revised_mainwindow();
        mw.Show();

        }

        // Insert code required on object creation below this point.
    }   
}
}

问题出在你的逻辑上。

此时执行if语句时splash_load.Value不是100,因为动画开始了,但到这里还没有结束。完成动画后您将如何检查此条件。使用 AnimationCompleted 事件来检查条件并显示您的 Main Window.