i got this WPF application, and here i made a Splashscreen (wfp window) with a processbar on it. (for now i just let it run with a timer to change that later on)
so far, this all seems to work pretty well.
but, the following happens:
– I start the build from the folder (../bin/release/ )
– Splash now appears on the screen and the processbar starts to run.
– at a full bar, it will start the main application (MainWindow)
but, this main window does not start on top now, it is behind the folder from where the exe was executed (in this case the ../release/ )
i have been looking around, but dont really understand how to use the snipits i find around on the internet, and dont really think those are the right fix.
rather use a decent fix then some workaround (if possible)
so, why does this happen, and how can i change this behavior to work properly? (so that main get displayed on top (non-persistent) after splash?)
some parts of the code:
in main
using ........
//etc etc...
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
//creating the exitmessage for use later on, after all, we want to use this in an other method.
string exitmessage = null;
public MainWindow()
{
//start new thread and use that for splashscreen.
Thread t = new Thread(new ThreadStart(SplashScreen));
t.SetApartmentState(ApartmentState.STA);
t.Start();
Thread.Sleep(5000);
//start mainwindow
InitializeComponent();
//end splash proc.
t.Abort();
//region //check lang
}
public void SplashScreen()
{
WpfApplication1.Window4 X = new WpfApplication1.Window4();
X.ShowDialog();
}
// region //etc.. app stuff
}
}
in window4 (splash)
using .....
//etc.. etc...
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window4.xaml
/// </summary>
public partial class Window4 : Window
{
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
public Window4()
{
InitializeComponent();
Timer1();
}
public void Timer1()
{
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0,0,0,0,25);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
if (progressBar1.Value == 100)
dispatcherTimer.Stop();
else
progressBar1.Value++;
}
}
}
hopefully someone can help me out here.
thanx!
don’t try to display splash in you MainWindow.. right way is that you should try creating a window having no border and no resize and stay on top.. and then call that window.show() in app.cs
here is an article defining how you can do this..
http://romenlaw.blogspot.com/2008/07/wpf-splash-with-progressbar.html
EDIT:
you can subscribe to progresschange event of backgroundworker. this will be fired whenever you call worker.ReportProgress() method from DoWork eventHandler
this line will be added after these lines in InitOperation class.
and in event handler for DoWork you can use
in worker_ProgressChanged event handler you can change progress of the bar.
Regards