How to open a child Window like a splash screen before MainWindow in WPF? -
How to open a child Window like a splash screen before MainWindow in WPF? -
i have 2 xaml. 1 mainwindow , other newwindow. want show newwindow 5 seconds, when programme run. , after 5 seconds, want show mainwindow.
how alter xaml in wpf?
here mainwindow.
<window x:class="wpfapplication2.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="mainwindow" height="350" width="525"> <grid>  </grid>       public partial class mainwindow : window {     public mainwindow()     {         initializecomponent();     } }    here newwindow.
<window x:class="wpfapplication2.newwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="newwindow" height="300" width="300"> <grid>  </grid>       public partial class newwindow : window {     public newwindow()     {         initializecomponent();     } }       
there plenty ways this. people suggested suggest not if you're trying create splash screen, there improve ways that. but.. here asked for:
using system.componentmodel; //remember  add together  public partial class mainwindow : window {     private backgroundworker waitingworker = new backgroundworker();     private newwindow mynewwindow = new newwindow();      public mainwindow()     {         initializecomponent();          waitingworker.dowork += waitingworker_dowork;         waitingworker.runworkercompleted += waitingworker_runworkercompleted;          waitingworker.runworkerasync();     }      private void waitingworker_runworkercompleted(object sender, runworkercompletedeventargs e)     {         mynewwindow.show();         this.close();     }      private void waitingworker_dowork(object sender, doworkeventargs e)     {         thread.sleep(5000);     } }    it's simple background worker waits 5 seconds, opens newwindow , close mainwindow. yes, can without background worker too, thread.sleep(5000); totally freeze gui ,  create little app unresponsive, need thread wait while main thread can  maintain gui alive. suggest study at least how background worker works.
here official msdn documentation, google friend , can find tons of tutorial , explanation it
 wpf 
 
Comments
Post a Comment