Skip to content

Instantly share code, notes, and snippets.

@khmylov
Created April 27, 2012 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khmylov/2511876 to your computer and use it in GitHub Desktop.
Save khmylov/2511876 to your computer and use it in GitHub Desktop.
Cleaned up WP7 App.xaml template
<Application
x:Class="$namespace$.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<Application.Resources>
<system:String x:Key="ApplicationTitle">APPLICATION TITLE</system:String>
<!-- Page margins -->
<Thickness x:Key="PageHeaderPanelMargin">12,17,0,28</Thickness>
<Thickness x:Key="PageNameLabelMargin">9,-7,0,0</Thickness>
<Thickness x:Key="PageContentPanelMargin">12,0</Thickness>
<Style x:Key="DefaultPageStyle" TargetType="phone:PhoneApplicationPage">
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="SupportedOrientations" Value="Portrait"/>
<Setter Property="Orientation" Value="PortraitUp"/>
<Setter Property="shell:SystemTray.IsVisible" Value="True"/>
</Style>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<shell:PhoneApplicationService />
</Application.ApplicationLifetimeObjects>
</Application>
using System.Diagnostics;
using System.Windows;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
namespace TrackYourKids.Phone
{
public partial class App
{
public static new App Current
{
get { return (App) Application.Current; }
}
public PhoneApplicationFrame RootFrame { get; private set; }
public App()
{
UnhandledException += OnUnhandledException;
InitializeComponent();
InitializePhoneApplication();
InitializeDebugEnvironment();
}
[Conditional("DEBUG")]
private void InitializeDebugEnvironment()
{
if (Debugger.IsAttached)
{
Application.Current.Host.Settings.EnableFrameRateCounter = true;
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
}
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (Debugger.IsAttached)
{
Debugger.Break();
}
}
private void OnUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached)
{
Debugger.Break();
}
}
private void InitializePhoneApplication()
{
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
RootFrame.NavigationFailed += OnNavigationFailed;
}
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
RootFrame.Navigated -= CompleteInitializePhoneApplication;
RootVisual = RootFrame;
}
}
}
@khmylov
Copy link
Author

khmylov commented May 15, 2012

Added PhoneApplicationService as Application.ApplicationLifetimeObjects to prevent null reference exception during debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment