启动窗口没有关闭- WPF
本文关键字:WPF 窗口 启动 | 更新日期: 2023-09-27 17:50:01
我有一个带有进度条的闪屏,一旦加载完成,主窗口应该打开。然而,主窗口根本不会打开,即使在进度条完全加载后,启动窗口仍然存在。怎么了?
在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.
}
}
}
问题是你的逻辑。
当if
语句在此时执行时,splash_load.Value
不是100,因为动画已经开始但直到此时才结束。在完成动画后,您必须检查此条件。使用Animation
的Completed
事件检查情况并显示主窗口