1
+ using Microsoft . UI . Xaml . Navigation ;
2
+
1
3
namespace DateCalculator . WinUI
2
4
{
3
5
/// <summary>
4
6
/// Provides application-specific behavior to supplement the default Application class.
5
7
/// </summary>
6
8
public partial class App : Application
7
9
{
10
+ private Window window = Window . Current ;
11
+
8
12
/// <summary>
9
13
/// Initializes the singleton application object. This is the first line of authored code
10
14
/// executed, and as such is the logical equivalent of main() or WinMain().
@@ -18,13 +22,30 @@ public App()
18
22
/// Invoked when the application is launched normally by the end user. Other entry points
19
23
/// will be used such as when the application is launched to open a specific file.
20
24
/// </summary>
21
- /// <param name="args ">Details about the launch request and process.</param>
22
- protected override void OnLaunched ( LaunchActivatedEventArgs args )
25
+ /// <param name="e ">Details about the launch request and process.</param>
26
+ protected override void OnLaunched ( LaunchActivatedEventArgs e )
23
27
{
24
- m_window = new MainWindow ( ) ;
25
- m_window ? . Activate ( ) ;
28
+ window ??= new Window ( ) ;
29
+
30
+ if ( window . Content is not Frame rootFrame )
31
+ {
32
+ rootFrame = new Frame ( ) ;
33
+ rootFrame . NavigationFailed += OnNavigationFailed ;
34
+ window . Content = rootFrame ;
35
+ }
36
+
37
+ _ = rootFrame . Navigate ( typeof ( MainPage ) , e . Arguments ) ;
38
+ window . Activate ( ) ;
26
39
}
27
40
28
- private Window ? m_window ;
41
+ /// <summary>
42
+ /// Invoked when Navigation to a certain page fails
43
+ /// </summary>
44
+ /// <param name="sender">The Frame which failed navigation</param>
45
+ /// <param name="e">Details about the navigation failure</param>
46
+ void OnNavigationFailed ( object sender , NavigationFailedEventArgs e )
47
+ {
48
+ throw new Exception ( "Failed to load Page " + e . SourcePageType . FullName ) ;
49
+ }
29
50
}
30
51
}
0 commit comments