From 6711b688db3f78c3f69eb56075a94848a86a4afa Mon Sep 17 00:00:00 2001
From: Vijay Anand E G <81947404+egvijayanand@users.noreply.github.com>
Date: Mon, 30 Sep 2024 23:45:50 +0530
Subject: [PATCH] Frame-based navigation and MVVM Toolkit temporary fix
---
.../DateCalculator.Maui.csproj | 1 +
.../DateCalculator.WinUI/App.xaml.cs | 31 ++++++++++++++++---
.../DateCalculator.WinUI.csproj | 1 +
.../DateCalculator.WinUI/Imports.cs | 1 +
.../Views/{MainWindow.xaml => MainPage.xaml} | 10 +++---
.../{MainWindow.xaml.cs => MainPage.xaml.cs} | 4 +--
.../DateCalculator.Maui.csproj | 1 +
7 files changed, 37 insertions(+), 12 deletions(-)
rename src/NET_8/DateCalculator/DateCalculator.WinUI/Views/{MainWindow.xaml => MainPage.xaml} (98%)
rename src/NET_8/DateCalculator/DateCalculator.WinUI/Views/{MainWindow.xaml.cs => MainPage.xaml.cs} (74%)
diff --git a/src/NET_8/DateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj b/src/NET_8/DateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj
index 07a63d6..8da6446 100644
--- a/src/NET_8/DateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj
+++ b/src/NET_8/DateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj
@@ -19,6 +19,7 @@
enable
DateCalculator
None
+ 10.0.19041.38
DateCalculator
diff --git a/src/NET_8/DateCalculator/DateCalculator.WinUI/App.xaml.cs b/src/NET_8/DateCalculator/DateCalculator.WinUI/App.xaml.cs
index 6082861..3d004cc 100644
--- a/src/NET_8/DateCalculator/DateCalculator.WinUI/App.xaml.cs
+++ b/src/NET_8/DateCalculator/DateCalculator.WinUI/App.xaml.cs
@@ -1,3 +1,5 @@
+using Microsoft.UI.Xaml.Navigation;
+
namespace DateCalculator.WinUI
{
///
@@ -5,6 +7,8 @@ namespace DateCalculator.WinUI
///
public partial class App : Application
{
+ private Window window = Window.Current;
+
///
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
@@ -18,13 +22,30 @@ public App()
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
///
- /// Details about the launch request and process.
- protected override void OnLaunched(LaunchActivatedEventArgs args)
+ /// Details about the launch request and process.
+ protected override void OnLaunched(LaunchActivatedEventArgs e)
{
- m_window = new MainWindow();
- m_window?.Activate();
+ window ??= new Window();
+
+ if (window.Content is not Frame rootFrame)
+ {
+ rootFrame = new Frame();
+ rootFrame.NavigationFailed += OnNavigationFailed;
+ window.Content = rootFrame;
+ }
+
+ _ = rootFrame.Navigate(typeof(MainPage), e.Arguments);
+ window.Activate();
}
- private Window? m_window;
+ ///
+ /// Invoked when Navigation to a certain page fails
+ ///
+ /// The Frame which failed navigation
+ /// Details about the navigation failure
+ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
+ {
+ throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
+ }
}
}
diff --git a/src/NET_8/DateCalculator/DateCalculator.WinUI/DateCalculator.WinUI.csproj b/src/NET_8/DateCalculator/DateCalculator.WinUI/DateCalculator.WinUI.csproj
index df5b9a2..4b3539e 100644
--- a/src/NET_8/DateCalculator/DateCalculator.WinUI/DateCalculator.WinUI.csproj
+++ b/src/NET_8/DateCalculator/DateCalculator.WinUI/DateCalculator.WinUI.csproj
@@ -9,6 +9,7 @@
true
true
None
+ 10.0.19041.38
enable
diff --git a/src/NET_8/DateCalculator/DateCalculator.WinUI/Imports.cs b/src/NET_8/DateCalculator/DateCalculator.WinUI/Imports.cs
index 30460a6..74de3f1 100644
--- a/src/NET_8/DateCalculator/DateCalculator.WinUI/Imports.cs
+++ b/src/NET_8/DateCalculator/DateCalculator.WinUI/Imports.cs
@@ -2,4 +2,5 @@
global using DateCalculator.WinUI.Views;
global using Microsoft.UI.Xaml;
+global using Microsoft.UI.Xaml.Controls;
global using Microsoft.UI.Xaml.Data;
diff --git a/src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainWindow.xaml b/src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainPage.xaml
similarity index 98%
rename from src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainWindow.xaml
rename to src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainPage.xaml
index b9d3cc9..3367d66 100644
--- a/src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainWindow.xaml
+++ b/src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainPage.xaml
@@ -1,6 +1,6 @@
-
-
+
@@ -115,5 +115,5 @@
-
-
+
+
diff --git a/src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainWindow.xaml.cs b/src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainPage.xaml.cs
similarity index 74%
rename from src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainWindow.xaml.cs
rename to src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainPage.xaml.cs
index 33e762e..6610bc7 100644
--- a/src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainWindow.xaml.cs
+++ b/src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainPage.xaml.cs
@@ -3,9 +3,9 @@ namespace DateCalculator.WinUI.Views
///
/// An empty window that can be used on its own or navigated to within a Frame.
///
- public sealed partial class MainWindow : Window
+ public sealed partial class MainPage : Page
{
- public MainWindow()
+ public MainPage()
{
this.InitializeComponent();
}
diff --git a/src/NET_8/UnifiedDateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj b/src/NET_8/UnifiedDateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj
index 2661209..43ede41 100644
--- a/src/NET_8/UnifiedDateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj
+++ b/src/NET_8/UnifiedDateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj
@@ -18,6 +18,7 @@
enable
DateCalculator.Maui
None
+ 10.0.19041.38
DateCalculator.Maui