Skip to content

Commit

Permalink
Frame-based navigation and MVVM Toolkit temporary fix
Browse files Browse the repository at this point in the history
  • Loading branch information
egvijayanand committed Sep 30, 2024
1 parent e23c5f0 commit 6711b68
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>DateCalculator</RootNamespace>
<WindowsPackageType>None</WindowsPackageType>
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>

<!-- Display name -->
<ApplicationTitle>DateCalculator</ApplicationTitle>
Expand Down
31 changes: 26 additions & 5 deletions src/NET_8/DateCalculator/DateCalculator.WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using Microsoft.UI.Xaml.Navigation;

namespace DateCalculator.WinUI
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
private Window window = Window.Current;

/// <summary>
/// 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().
Expand All @@ -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.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
/// <param name="e">Details about the launch request and process.</param>
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;
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<WindowsPackageType>None</WindowsPackageType>
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>

<!-- Project Options -->
<Nullable>enable</Nullable>
Expand Down
1 change: 1 addition & 0 deletions src/NET_8/DateCalculator/DateCalculator.WinUI/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Window
x:Class="DateCalculator.WinUI.Views.MainWindow"
<Page
x:Class="DateCalculator.WinUI.Views.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="using:DateCalculator.WinUI.Converters"
Expand All @@ -9,7 +9,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:DateCalculator.ViewModels"
mc:Ignorable="d">
<Window.Content>
<Page.Content>
<StackPanel
x:Name="content"
Margin="30">
Expand Down Expand Up @@ -115,5 +115,5 @@
<TextBlock Text="{Binding DiffInDays}" />
</StackPanel>
</StackPanel>
</Window.Content>
</Window>
</Page.Content>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ namespace DateCalculator.WinUI.Views
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
public sealed partial class MainPage : Page
{
public MainWindow()
public MainPage()
{
this.InitializeComponent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>DateCalculator.Maui</RootNamespace>
<WindowsPackageType>None</WindowsPackageType>
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>

<!-- Display name -->
<ApplicationTitle>DateCalculator.Maui</ApplicationTitle>
Expand Down

0 comments on commit 6711b68

Please sign in to comment.