Created
November 21, 2015 00:51
-
-
Save Stephanvs/7bb2cdc9dbf15cb7a90f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Windows.ApplicationModel; | |
using Windows.ApplicationModel.Activation; | |
using Windows.UI; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using Windows.UI.Xaml.Navigation; | |
using Cirrious.CrossCore; | |
using Cirrious.MvvmCross.ViewModels; | |
namespace XXXX.WinUniversal | |
{ | |
/// <summary> | |
/// Provides application-specific behavior to supplement the default Application class. | |
/// </summary> | |
sealed partial class App : Application | |
{ | |
/// <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(). | |
/// </summary> | |
public App() | |
{ | |
this.InitializeComponent(); | |
this.Suspending += OnSuspending; | |
} | |
/// <summary> | |
/// 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="e">Details about the launch request and process.</param> | |
protected override void OnLaunched(LaunchActivatedEventArgs e) | |
{ | |
#if DEBUG | |
if (System.Diagnostics.Debugger.IsAttached) | |
{ | |
//this.DebugSettings.EnableFrameRateCounter = true; | |
} | |
#endif | |
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 (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 | |
var setup = new Setup(rootFrame); | |
setup.Initialize(); | |
var startup = Mvx.Resolve<IMvxAppStart>(); | |
startup.Start(); | |
} | |
// Ensure the current window is active | |
Window.Current.Activate(); | |
} | |
/// <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); | |
} | |
/// <summary> | |
/// Invoked when application execution is being suspended. Application state is saved | |
/// without knowing whether the application will be terminated or resumed with the contents | |
/// of memory still intact. | |
/// </summary> | |
/// <param name="sender">The source of the suspend request.</param> | |
/// <param name="e">Details about the suspend request.</param> | |
private void OnSuspending(object sender, SuspendingEventArgs e) | |
{ | |
var deferral = e.SuspendingOperation.GetDeferral(); | |
//TODO: Save application state and stop any background activity | |
deferral.Complete(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<views:MvxWindowsPage | |
x:Class="XXXX.WinUniversal.Views.HomeView" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:views="using:Cirrious.MvvmCross.WindowsUWP.Views" | |
mc:Ignorable="d"> | |
<Grid Background="{ThemeResource BackgroundBrush}"> | |
<SplitView x:Name="RootSplitView" | |
DisplayMode="CompactInline" | |
IsPaneOpen="false" | |
CompactPaneLength="48" | |
OpenPaneLength="200" | |
PaneBackground="{ThemeResource BackgroundBrush}"> | |
<SplitView.Pane> | |
<controls:NavMenuListView x:Name="NavMenuList" | |
TabIndex="3" | |
Margin="0,48,0,0" | |
ScrollViewer.HorizontalScrollMode="Disabled" | |
ScrollViewer.VerticalScrollMode="Disabled" | |
ItemInvoked="NavMenuList_OnItemInvoked" | |
ItemContainerStyle="{StaticResource NavMenuItemContainerStyle}" | |
ItemTemplate="{StaticResource NavMenuItemTemplate}"> | |
<controls:NavMenuListView.Footer> | |
<Button x:Name="SettingsButton" | |
ToolTipService.ToolTip="Settings" | |
TabIndex="4" | |
Style="{StaticResource NavigationSettingsButtonStyle}" | |
Width="{Binding ItemsPanelRoot.Width, ElementName=NavMenuList}" | |
HorizontalAlignment="{Binding ItemsPanelRoot.HorizontalAlignment, ElementName=NavMenuList}" | |
Foreground="{ThemeResource ForegroundBrush}" | |
Click="SettingsButton_OnClick" /> | |
</controls:NavMenuListView.Footer> | |
</controls:NavMenuListView> | |
</SplitView.Pane> | |
<SplitView.Content> | |
<ScrollViewer HorizontalScrollMode="Disabled" | |
VerticalScrollBarVisibility="Auto"> | |
<!-- OnNavigatingToPage we synchronize the selected item in the nav menu with the current page. | |
OnNavigatedToPage we move keyboard focus to the first item on the page after it's loaded. --> | |
<Frame x:Name="MainContent"> | |
<Frame.ContentTransitions> | |
<TransitionCollection> | |
<NavigationThemeTransition> | |
<NavigationThemeTransition.DefaultNavigationTransitionInfo> | |
<EntranceNavigationTransitionInfo /> | |
</NavigationThemeTransition.DefaultNavigationTransitionInfo> | |
</NavigationThemeTransition> | |
</TransitionCollection> | |
</Frame.ContentTransitions> | |
<!-- | |
You might want to add some initial content here, or in the `Init` of the HomeViewModel invoke another `ShowViewModel<T>();` | |
That would replace the empty frame with the contents of the corresponding view | |
--> | |
</Frame> | |
</ScrollViewer> | |
</SplitView.Content> | |
</SplitView> | |
<!-- Declared last to have it rendered above everything else, but it needs to be the first item in the tab sequence. --> | |
<ToggleButton x:Name="TogglePaneButton" | |
TabIndex="1" | |
Style="{StaticResource SplitViewTogglePaneButtonStyle}" | |
IsChecked="{Binding IsPaneOpen, ElementName=RootSplitView, Mode=TwoWay}" | |
Unchecked="TogglePaneButton_Checked" | |
AutomationProperties.Name="Menu" | |
ToolTipService.ToolTip="Menu" | |
Foreground="{ThemeResource ForegroundBrush}" /> | |
</Grid> | |
</views:MvxWindowsPage> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment