Logo
CAR REVIEW
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
PREGNANCY
 
 
Windows Phone

Windows Phone 8 : Developing for the Phone - Application Lifecycle (part 1)

5/24/2013 5:50:44 PM

When you create a new Windows Phone project, the project contains all the files you need to get started building a phone application. There are several key files, but let’s start with the XAML files. As you can see in Figure 1, the App.xaml and MainPage.xaml files have code files associated with them (they have a “.cs” extension because this project is a C# project).

Image

FIGURE 1 Important files in a new project

These code files represent the code that goes with the main page and the application class, respectively. The App.xaml file is where we can store application-wide resources. The class that goes with the App.xaml file represents the application itself. In fact, when your application is started it is this file (not MainPage.xaml’s class) that starts up first. This class is called the App class, and it derives from the Application class:

public partial class App : Application
{
  // ...
}

This class is used to store application-wide code/data. For example, the App class stores the main frame for your entire application. This RootFrame property exposes the frame in which all your pages will display:

public partial class App : Application
{
  /// <summary>
  /// Provides easy access to the root frame
  /// of the Phone Application.
  /// </summary>
  /// <returns>The root frame of the Phone Application.</returns>
  public PhoneApplicationFrame RootFrame { get; private set; }

  // ...
}

Although the App class represents your running application, it is exposed as a singleton via the Application class’s Current property. For example, to get at the current application class anywhere in your code, you would call the static Current property on the App class:

Application theApplication = App.Current;

You should notice that the Current property returns an instance of the Application class (the base class). If you want to access properties on the App class instance itself, you must cast it to the App class, like so:

App theApplication = (App)App.Current;
var frame = theApplication.RootFrame;
// ...or...
frame = ((App)App.Current).RootFrame;

During initialization of the App class, the RootFrame is created and shown to the user of the phone. But if you look through the code for the App class, it might not seem obvious how the MainPage.xaml is actually shown. The trick is in the third file I highlighted in Figure 1: WMAppManifest.xml.

When you open the WMAppManifest.xml file (by double-clicking it), it opens an editor that enables you to change information about the phone app. You can see this editor shown in Figure 2.

Image

FIGURE 2 The WMAppManifest.xml Editor

Highlighted in Figure 2 is the item called Navigation Page; this is the URI to the starting page of your application. The manifest file contains a variety of settings that help the phone (and the Marketplace) determine information about your application.

After an instance of the App class is created and initialized, the application is told to navigate to the page in the Navigation Page element of the WMAppManifest.xml file. This is how your MainPage.xaml is shown.


Changing the Name of the XAML File

If you decide to change the name of the XAML file (and the underlying class file), you must be sure to change the name in the x:Class declaration as well.


Using a mix of the application class and the manifest file, your application gracefully starts up with your first page being shown. This is similar to how running a typical desktop application starts as well, but the lifecycle of your phone application is actually much different from that.

Other -----------------
- Windows Phone 8 : Designing for the Phone - Implementing the Look and Feel of the Phone
- Windows Phone 8 : Designing for the Phone - Designing with Visual Studio
- Windows Phone 7 : 3D Game Development (part 4) - Rendering 3D Models
- Windows Phone 7 : 3D Game Development (part 3) - The Game Class
- Windows Phone 7 : 3D Game Development (part 2) - Rendering 3D Primitives
- Windows Phone 7 : 3D Game Development (part 1) - 3D Game Concepts
- Windows Phone 8 : Phone-Specific Design (part 3) - Using the Pivot Control in Blend
- Windows Phone 8 : Phone-Specific Design (part 2) - Using the Panorama Control in Blend
- Windows Phone 8 : Phone-Specific Design (part 1) - The ApplicationBar in Blend
- Windows Phone 7 : AlienShooter Enhancements (part 2) - Tombstone Support, Particle System
- Windows Phone 7 : AlienShooter Enhancements (part 1) - Load and Save Game State
- Windows Phone 7 Programming Model : Application Execution Model
- Windows Phone 7 Programming Model : Bing Maps Control
- Windows Phone 8 : Designing for the Phone - Blend Basics (part 4) - Working with Behaviors
- Windows Phone 8 : Designing for the Phone - Blend Basics (part 3) - Creating Animations
- Windows Phone 8 : Designing for the Phone - Blend Basics (part 2) - Brushes
- Windows Phone 8 : Designing for the Phone - Blend Basics (part 1) - Layout
- Windows Phone 8 : Designing for the Phone - Microsoft Expression Blend
- Windows Phone 7 Programming Model : Asynchronous Programming - Background Threads
- Windows Phone 8 : Designing for the Phone - Deciding on an Application Paradigm
 
 
Most view of day
- BizTalk 2006 : Getting Started with Pipeline Development (part 3) - Configuring Recoverable Interchanges, Using the Default Pipelines
- Windows Server 2012 Requirements and Installation : Installing Server 2012 (part 1) - Server Core Install
- Configuring Startup and Troubleshooting Startup Issues : Important Startup Files, How to Configure Startup Settings
- BizTalk Server 2009 Operations : Maintaining the BizTalk Group (part 2) - Backup Procedures
- Windows Server 2012 : Managing networking using Windows PowerShell (part 2) - Examples of network-administration tasks
- Microsoft Dynamic GP 2010 : Providing clean vendor information by properly closing Purchase Orders, Protecting against information loss by printing Fixed Asset Reports
- Microsoft Exchange Server 2010 : Managing Connectivity with Hub Transport Servers - Send and Receive Connectors (part 1)
- Microsoft PowerPoint 2010 : Finalizing Your Slide Show - Reviewing Your Presentation
- SQL Server 2008 R2 : Performance Monitoring Tools (part 9) - Creating an Extended Events Session
- Windows Server 2003 : Protecting Hosts with Windows Host Firewalls - Internet Connection Sharing
Top 10
- Microsoft Word 2010 : Collaborating with Others - Limiting What Other Users Can Do to a Document
- Microsoft Word 2010 : Adding Graphics to Your Documents - Drawing Shapes in Word (part 2) - Modifying an AutoShape
- Microsoft Word 2010 : Adding Graphics to Your Documents - Drawing Shapes in Word (part 1) - Drawing an AutoShape
- Microsoft Exchange Server 2013 : Mailbox management - Setting mailbox permissions (part 5) - Outlook delegate access
- Microsoft Exchange Server 2013 : Mailbox management - Setting mailbox permissions (part 4) - Sending messages on behalf of other users
- Microsoft Exchange Server 2013 : Mailbox management - Setting mailbox permissions (part 3) - Mailbox auto-mapping through Autodiscover
- Microsoft Exchange Server 2013 : Mailbox management - Setting mailbox permissions (part 2) - Managing Full Access permission
- Microsoft Exchange Server 2013 : Mailbox management - Setting mailbox permissions (part 1) - Mailbox delegation
- Microsoft Exchange Server 2013 : Mailbox management - Health mailboxes
- Microsoft Exchange Server 2013 : Mailbox management - Discovery mailboxes - Creating additional discovery mailboxes
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro