C# 飞溅窗口不';t关闭-WPF

C# 飞溅窗口不';t关闭-WPF,c#,wpf,xaml,splash-screen,expression-blend,C#,Wpf,Xaml,Splash Screen,Expression Blend,我有一个带有进度条的启动屏幕,一旦完全加载,主窗口就会打开。但是,主窗口根本不会打开,即使进度条已完全加载,飞溅窗口仍会保留。怎么了 在App.xaml中,我设置了StartupUri=“SplashWindow.xaml” 启动窗口代码: using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.W

我有一个带有进度条的启动屏幕,一旦完全加载,主窗口就会打开。但是,主窗口根本不会打开,即使进度条已完全加载,飞溅窗口仍会保留。怎么了

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

启动窗口代码:

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.
    }   
}
}
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Shapes;
使用系统线程;
使用System.Windows.Media.Animation;
名称空间项目1
{
/// 
///SplashWindow.xaml的交互逻辑
/// 
公共部分类窗口:窗口
{
公共窗口()
{
this.InitializeComponent();
持续时间=新的持续时间(System.TimeSpan.FromSeconds(10));
DoubleAnimation DoubleAnimation=新的DoubleAnimation(飞溅加载最大值,持续时间);
splash_load.BeginAnimation(ProgressBar.ValueProperty,doubleanimation);
if(splash\u load.Value==100)//如果进度条(Name=“splash\u load”)完全加载
{
//关闭飞溅窗口
这个。关闭();
//打开主窗口
var mw=新修订的_主窗口();
mw.Show();
}
//在此点下方插入创建对象所需的代码。
}   
}
}

问题在于您的逻辑


当此时执行
if
语句时,
splash\u load.Value
不是100,因为动画已经开始,但直到此时才结束。您将如何在完成动画后检查此条件。使用
Completed
event of
Animation
检查状况并显示主窗口。

您无法关闭尚未显示的内容,我已经有一段时间没有使用WPF了,但我确定它有一个onshown事件或类似事件?您的逻辑似乎不正确,请尝试此链接以获取其他信息example@TommyGrovnes字体我试过了,但是我遇到了DispatchPriority的问题。可能与我附加了一个事件处理程序来处理双动画的已完成事件的副本。成功了。非常感谢。