I have a splash screen with a progress bar, and once it is loaded completely the main window should open. However the main window doesn't open at all, and the splash window remains even after the progress bar is fully loaded. What is wrong?
In App.xaml, I have set StartupUri="SplashWindow.xaml"
Splash Window Code:
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.
}
}
}
Issue is with your logic.
When the if
statement executes at that time splash_load.Value
is not 100, because the animation is started but not finished till this point. Some how you will have to check this condition after completing the animation. Use Completed
event of Animation
to check for the condition and show your Main Window.