Skip to content

Commit 050db1a

Browse files
authored
Merge pull request #96 from egvijayanand/working
WinUI Frame-based navigation and MVVM Toolkit temporary fix
2 parents e23c5f0 + 6711b68 commit 050db1a

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

src/NET_8/DateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<ImplicitUsings>enable</ImplicitUsings>
2020
<RootNamespace>DateCalculator</RootNamespace>
2121
<WindowsPackageType>None</WindowsPackageType>
22+
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
2223

2324
<!-- Display name -->
2425
<ApplicationTitle>DateCalculator</ApplicationTitle>

src/NET_8/DateCalculator/DateCalculator.WinUI/App.xaml.cs

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
using Microsoft.UI.Xaml.Navigation;
2+
13
namespace DateCalculator.WinUI
24
{
35
/// <summary>
46
/// Provides application-specific behavior to supplement the default Application class.
57
/// </summary>
68
public partial class App : Application
79
{
10+
private Window window = Window.Current;
11+
812
/// <summary>
913
/// Initializes the singleton application object. This is the first line of authored code
1014
/// executed, and as such is the logical equivalent of main() or WinMain().
@@ -18,13 +22,30 @@ public App()
1822
/// Invoked when the application is launched normally by the end user. Other entry points
1923
/// will be used such as when the application is launched to open a specific file.
2024
/// </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)
2327
{
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();
2639
}
2740

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+
}
2950
}
3051
}

src/NET_8/DateCalculator/DateCalculator.WinUI/DateCalculator.WinUI.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<UseWinUI>true</UseWinUI>
1010
<EnableMsixTooling>true</EnableMsixTooling>
1111
<WindowsPackageType>None</WindowsPackageType>
12+
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
1213

1314
<!-- Project Options -->
1415
<Nullable>enable</Nullable>

src/NET_8/DateCalculator/DateCalculator.WinUI/Imports.cs

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
global using DateCalculator.WinUI.Views;
33

44
global using Microsoft.UI.Xaml;
5+
global using Microsoft.UI.Xaml.Controls;
56
global using Microsoft.UI.Xaml.Data;

src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainWindow.xaml renamed to src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainPage.xaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<Window
3-
x:Class="DateCalculator.WinUI.Views.MainWindow"
2+
<Page
3+
x:Class="DateCalculator.WinUI.Views.MainPage"
44
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
xmlns:conv="using:DateCalculator.WinUI.Converters"
@@ -9,7 +9,7 @@
99
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1010
xmlns:vm="using:DateCalculator.ViewModels"
1111
mc:Ignorable="d">
12-
<Window.Content>
12+
<Page.Content>
1313
<StackPanel
1414
x:Name="content"
1515
Margin="30">
@@ -115,5 +115,5 @@
115115
<TextBlock Text="{Binding DiffInDays}" />
116116
</StackPanel>
117117
</StackPanel>
118-
</Window.Content>
119-
</Window>
118+
</Page.Content>
119+
</Page>

src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainWindow.xaml.cs renamed to src/NET_8/DateCalculator/DateCalculator.WinUI/Views/MainPage.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ namespace DateCalculator.WinUI.Views
33
/// <summary>
44
/// An empty window that can be used on its own or navigated to within a Frame.
55
/// </summary>
6-
public sealed partial class MainWindow : Window
6+
public sealed partial class MainPage : Page
77
{
8-
public MainWindow()
8+
public MainPage()
99
{
1010
this.InitializeComponent();
1111
}

src/NET_8/UnifiedDateCalculator/DateCalculator.Maui/DateCalculator.Maui.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ImplicitUsings>enable</ImplicitUsings>
1919
<RootNamespace>DateCalculator.Maui</RootNamespace>
2020
<WindowsPackageType>None</WindowsPackageType>
21+
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
2122

2223
<!-- Display name -->
2324
<ApplicationTitle>DateCalculator.Maui</ApplicationTitle>

0 commit comments

Comments
 (0)