我有一个带有进度条的启动画面,一旦完全加载,主窗口就会打开。但是主窗口根本不打开,并且在进度条完全加载后,启动窗口仍然保持不变。有什么问题?
在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.
}
}
}
答案 0 :(得分:0)
问题与你的逻辑有关。
当if
语句执行时splash_load.Value
不是100,因为动画已启动但直到此时才结束。完成动画后,您将如何检查此条件。使用Completed
Animation
事件检查条件并显示主窗口。