Last active
August 29, 2015 14:01
-
-
Save jossef/c6de37e25bbaeaa7e029 to your computer and use it in GitHub Desktop.
Response for http://stackoverflow.com/questions/23842009/open-new-window-after-splash-window-in-wpf/23843416#23843416
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Application x:Class="WpfApplication2.App" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | |
<Application.Resources> | |
</Application.Resources> | |
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Data; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using System.Windows; | |
namespace WpfApplication2 | |
{ | |
/// <summary> | |
/// Interaction logic for App.xaml | |
/// </summary> | |
public partial class App : Application | |
{ | |
async protected override void OnStartup(StartupEventArgs e) | |
{ | |
base.OnStartup(e); | |
// Create and show SplashWindow | |
SplashWindow splashWindow = new SplashWindow(); | |
splashWindow.Show(); | |
// Let's wait 3 seconds | |
await Task.Delay(3000); | |
// Create and show the SelectionWindow | |
SelectionWindow selectionWindow = new SelectionWindow(); | |
selectionWindow.Show(); | |
// Hide the SplashWindow we previosly created | |
splashWindow.Close(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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"> | |
<StackPanel> | |
<Label>This is the main window :)</Label> | |
</StackPanel> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
using System.Xml.Linq; | |
namespace WpfApplication2 | |
{ | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="WpfApplication2.SelectionWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="SelectionWindow" Height="300" Width="300"> | |
<StackPanel> | |
<Button Click="Button_Click">Click to open MainWindow</Button> | |
</StackPanel> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
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; | |
namespace WpfApplication2 | |
{ | |
/// <summary> | |
/// Interaction logic for SelectionWindow.xaml | |
/// </summary> | |
public partial class SelectionWindow : Window | |
{ | |
public SelectionWindow() | |
{ | |
InitializeComponent(); | |
} | |
private void Button_Click(object sender, RoutedEventArgs e) | |
{ | |
// Create and show MainWindow | |
var mainWindow = new MainWindow(); | |
mainWindow.Show(); | |
// Closes SelectionWindow | |
this.Close(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="WpfApplication2.SplashWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="SplashWindow" Height="300" Width="300"> | |
<StackPanel> | |
<Label FontSize="50">Splash Screen</Label> | |
</StackPanel> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
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; | |
namespace WpfApplication2 | |
{ | |
/// <summary> | |
/// Interaction logic for SplashWindow.xaml | |
/// </summary> | |
public partial class SplashWindow : Window | |
{ | |
public SplashWindow() | |
{ | |
InitializeComponent(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void OnStartup(StartupEventArgs e) | |
{ | |
base.OnStartup(e); | |
// Create and show SplashWindow | |
SplashWindow splashWindow = new SplashWindow(); | |
splashWindow.Show(); | |
var thread = new System.Threading.Thread(p => | |
{ | |
System.Threading.Thread.Sleep(3000); | |
Dispatcher.Invoke(() => | |
{ | |
// Create and show the SelectionWindow | |
SelectionWindow selectionWindow = new SelectionWindow(); | |
selectionWindow.Show(); | |
// Hide the SplashWindow we previosly created | |
splashWindow.Close(); | |
}); | |
}); | |
thread.Start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment