Windowing and Page Navigation: Developer's Guide To Windows 10

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Windowing and Page Navigation

Developer’s Guide to Windows 10


Agenda
Layout
Navigation
Handling Back Navigation
Layout
Minimum size
Minimum size of the window on resize
ApplicationView.GetForCurrentView().
SetPreferredMinSize(new size(width, height)))
Check return value (ENUM)
Resize
Programmatic window resize
ApplicationView.GetForCurrentView().
TryResizeView(new size(width, height)))
Check return value (Boolean)
Understanding immersive mode
Non-resizable on mobile
Window is always full screen on Mobile
Full screen on tablets/convertibles when in Tablet
mode

Limited sizing options


On Tablet, apps can be docked left or right, or on
large displays at one of the corners

Full screen mode for apps


on Desktop
Developer can now request Full Screen
Developer can now test Full Screen
Windowing
Windows.ApplicationModel.Core
.CoreApplication.CreateNewView()
Windows.UI.ViewManagement
.ApplicationViewSwitcher.SwitchAsync()
Windows.UI.ViewManagement
.ApplicationViewSwitcher.TryShowAsStandaloneAsync()
Available across all of Windows 10
New view must call Window.Activate()
Navigation
Frame.Navigate
Send to a type
Pass a string
Navigation service
Part of Template 10 project template

private void Goto2(object sender, Windows.UI.Xaml.RoutedEventArgs e)


{
var app = App.Current as Common.BootStrapper;
var nav = app.NavigationService;
nav.Navigate(typeof(Views.Page2), "My parameter value");
}
Navigation parameters
Page.OnNavigatedTo()
Standard in Windows

ViewModel.OnNavigatedTo
With Template 10 project template

public override void OnNavigatedTo(string parameter,


NavigationMode mode, IDictionary<string, object> state)
{
this.Parameter = parameter?.ToString() ?? "Empty";
}
Demo: Navigation parameters
Handling Back Navigation
Shell-drawn back button for Mobile and Tablet
Desktop, Windowed mode:
Opt-in, shell-drawn back button on Title Bar

if
if (Frame.CanGoBack)
(Frame.CanGoBack)
{{
// Setting this visible is ignored on Mobile and when in tablet mode!
// Setting this visible is ignored on Mobile and when in tablet mode!
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility ==
AppViewBackButtonVisibility.Visible;
AppViewBackButtonVisibility.Visible;
}}
Desktop, Windowed mode:
Or provide your own on-canvas Back Button
If the user has nowhere to go back to,
remove the back button from your UI
Back Navigation
Back navigates back within app page history, then to
previous app
Essentially same as Phone 8.1

Backing out does not close the app


Back out from launch page causes app to suspend

And, a new scenario for tablet


In split screen, there is a [back stack] for each side of the screen

BackRequested UWP API event


Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
Standard BackRequested handler
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
...    
    // Handle Back Requests
    SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
}

public event EventHandler<BackRequestedEventArgs> OnBackRequested;

private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
    if (OnBackRequested != null) { OnBackRequested(this, e); }

    // Check that no-one has already handled this
    if (!e.Handled)
    {
        // Default is to navigate back within the Frame
        Frame frame = Window.Current.Content as Frame;
        if (frame.CanGoBack)
        {
            frame.GoBack();
            // Signal handled so that system doesn't navigate back through app stack
            e.Handled = true;
        }
    }
}
Back support
Support gestures
Windows + backspace
Hardware back button
Keyboard back button
Mouse back button

Some guidance
Don’t strand users
Don’t hijack back
Demo: Back Navigation
Review
Layout
Navigation
Handling Back Navigation
© 2015 Microsoft Corporation. All rights reserved.

You might also like