Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mwv: URIs to allow opening the app directly to a specific page #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 40 additions & 57 deletions NewModernWinver/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Diagnostics;
using Windows.UI.ViewManagement;

namespace NewModernWinver
{
Expand All @@ -37,33 +38,10 @@ protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
ProtocolActivatedEventArgs e = args as ProtocolActivatedEventArgs;

// TODO: Handle URI activation
// The received URI is eventArgs.Uri.AbsoluteUri

Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;


// Place the frame in the current Window
Window.Current.Content = rootFrame;
}

// Always navigate for a protocol launch
rootFrame.Navigate(typeof(MainPage));


// Ensure the current window is active
Window.Current.Activate();
Frame rootFrame = InitializeView();
rootFrame.Navigate(typeof(MainPage), e.Uri.AbsoluteUri);
}
}

Expand All @@ -74,37 +52,8 @@ protected override void OnActivated(IActivatedEventArgs args)
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;

if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}

// Place the frame in the current Window
Window.Current.Content = rootFrame;
}

if (e.PrelaunchActivated == false)
{
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
Frame rootFrame = InitializeView();
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}

/// <summary>
Expand All @@ -130,5 +79,39 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
//TODO: Save application state and stop any background activity
deferral.Complete();
}

/// <summary>
/// Initializes the current window if necessary.
/// </summary>
/// <returns>The current window's root frame.</returns>
private Frame InitializeView()
{
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (!(Window.Current.Content is Frame rootFrame))
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;

// Place the frame in the current Window
Window.Current.Content = rootFrame;

// Before ensuring activation, set the preferred launch view size
var currView = ApplicationView.GetForCurrentView();
var size = new Size(436, 500);
currView.SetPreferredMinSize(size);

ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
ApplicationView.PreferredLaunchViewSize = size;

currView.TryResizeView(size);
}

// Ensure the current window is active
Window.Current.Activate();

return rootFrame;
}
}
}
2 changes: 1 addition & 1 deletion NewModernWinver/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</GridView>


<muxc:NavigationView x:Name="nvTopLevelNav" Margin="0,110,0,0" muxc:BackdropMaterial.ApplyToRootOrPageBackground="True" Background="Transparent" PaneDisplayMode="Top" IsBackButtonVisible="Collapsed" IsSettingsVisible="False" Loaded="nvTopLevelNav_Loaded" ItemInvoked="nvTopLevelNav_ItemInvoked" FlowDirection="LeftToRight" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" UseLayoutRounding="True" ScrollViewer.HorizontalScrollBarVisibility="Visible">
<muxc:NavigationView x:Name="nvTopLevelNav" Margin="0,110,0,0" muxc:BackdropMaterial.ApplyToRootOrPageBackground="True" Background="Transparent" PaneDisplayMode="Top" IsBackButtonVisible="Collapsed" IsSettingsVisible="False" ItemInvoked="nvTopLevelNav_ItemInvoked" FlowDirection="LeftToRight" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" UseLayoutRounding="True" ScrollViewer.HorizontalScrollBarVisibility="Visible">
<muxc:NavigationView.MenuItems>
<muxc:NavigationViewItem Tag="Nav_About">
<TextBlock Tag="Nav_About">About</TextBlock>
Expand Down
65 changes: 38 additions & 27 deletions NewModernWinver/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Windows.UI.Xaml.Controls;
using System.Runtime.InteropServices;
using Microsoft.Toolkit.Uwp.Helpers;
using NewModernWinver.Views;
using Windows.UI.Xaml.Navigation;


// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
Expand All @@ -20,20 +22,16 @@ namespace NewModernWinver

public sealed partial class MainPage : Page
{
ApplicationView appView;
int build;

public MainPage()
{
appView = ApplicationView.GetForCurrentView();
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
build = SystemInformation.Instance.OperatingSystemVersion.Build;
appView.SetPreferredMinSize(new Size(436, 635)); // STARTS HERE
ApplicationView.PreferredLaunchViewSize = new Size(436, 635); // JUMPS HERE WHY DOES THIS RESIZE
var Listener = new ThemeListener();
Listener.ThemeChanged += Listener_ThemeChanged;

InitializeComponent();
NavigationCacheMode = NavigationCacheMode.Required;

gvFrame1.Navigate(typeof(Views.AboutPage));
gvFrame2.Navigate(typeof(Views.SystemPage));
Expand Down Expand Up @@ -68,28 +66,16 @@ public MainPage()

}

ApplicationView appView = ApplicationView.GetForCurrentView();
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

appView.TitleBar.BackgroundColor = Colors.Transparent;
appView.TitleBar.ButtonBackgroundColor = Colors.Transparent;
appView.TitleBar.InactiveBackgroundColor = Colors.Transparent;
appView.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
appView.TryResizeView(new Size(436, 635));
}

#region NavigationView event handlers
private void nvTopLevelNav_Loaded(object sender, RoutedEventArgs e)
{
foreach (Microsoft.UI.Xaml.Controls.NavigationViewItem item in nvTopLevelNav.MenuItems)
{
if (item is Microsoft.UI.Xaml.Controls.NavigationViewItem && item.Tag.ToString() == "Nav_About")
{
nvTopLevelNav.SelectedItem = item;
break;
}
}
contentFrame.Navigate(typeof(Views.AboutPage));
}

private void Listener_ThemeChanged(ThemeListener sender)
{
var theme = sender.CurrentTheme;
Expand Down Expand Up @@ -130,10 +116,6 @@ private void Listener_ThemeChanged(ThemeListener sender)
}
}

private void nvTopLevelNav_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
}

private void nvTopLevelNav_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs args)
{
if (args.IsSettingsInvoked)
Expand All @@ -149,24 +131,53 @@ private void nvTopLevelNav_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView
switch (ItemContent.Tag)
{
case "Nav_About":
contentFrame.Navigate(typeof(Views.AboutPage));
contentFrame.Navigate(typeof(AboutPage));
break;

case "Nav_System":
contentFrame.Navigate(typeof(Views.SystemPage));
contentFrame.Navigate(typeof(SystemPage));
break;

case "Nav_Theme":
contentFrame.Navigate(typeof(Views.ThemePage));
contentFrame.Navigate(typeof(ThemePage));
break;

case "Nav_Links":
contentFrame.Navigate(typeof(Views.LinksPage));
contentFrame.Navigate(typeof(LinksPage));
break;
}
}
}
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter is string param)
{
switch (param)
{
case "mwv:system":
contentFrame.Navigate(typeof(SystemPage));
nvTopLevelNav.SelectedItem = nvTopLevelNav.MenuItems[1];
break;

case "mwv:theme":
contentFrame.Navigate(typeof(ThemePage));
nvTopLevelNav.SelectedItem = nvTopLevelNav.MenuItems[2];
break;

case "mwv:links":
contentFrame.Navigate(typeof(LinksPage));
nvTopLevelNav.SelectedItem = nvTopLevelNav.MenuItems[3];
break;

default:
contentFrame.Navigate(typeof(AboutPage));
nvTopLevelNav.SelectedItem = nvTopLevelNav.MenuItems[0];
break;
}
}
}
#endregion

private void okButton_Click(object sender, RoutedEventArgs e)
Expand Down