+ All Categories
Home > Technology > Fundamental Concepts for Building a Windows Phone 7 App

Fundamental Concepts for Building a Windows Phone 7 App

Date post: 24-May-2015
Category:
Upload: jeff-smoley
View: 1,751 times
Download: 1 times
Share this document with a friend
Description:
This presentation highlights some experiences of building a Windows Phone 7 app. It details out what you need to know when getting started along with some of the fundamental concepts of Windows Phone 7, Silverlight and XAML. It also cover some of the new features in the latest version of Windows Phone 7.5 (AKA Mango).
Popular Tags:
32
Fundamental Concepts for Building a Windows Phone 7 App Presented by Jeff Smoley, Software Architect @ W3i [email protected]
Transcript
Page 1: Fundamental Concepts for Building a Windows Phone 7 App

Fundamental Concepts for Building a Windows Phone 7 App

Presented by Jeff Smoley, Software Architect @ W3i

[email protected]

Page 2: Fundamental Concepts for Building a Windows Phone 7 App

The Win Phone 7 Language

Silverlight

C#, VB .Net

XAML

XNA

Page 3: Fundamental Concepts for Building a Windows Phone 7 App

Tools

Tools are free – App Hub

Visual Studio 2010 Express For Windows Phone

Expression Blend 4 for Windows Phone

Silverlight Toolkit – CodePlex

Download the Silverlight for Windows Phone Toolkit

Page 5: Fundamental Concepts for Building a Windows Phone 7 App

Execution Model • Execution Model Overview for

Windows Phone – MSDN

• No need to restore state when app is reactivated when returning from Dormant state.

• IsApplicationInstancePerserved

• True = Dormant

• False = Tombstoned

Page 6: Fundamental Concepts for Building a Windows Phone 7 App

Frame and Page Navigation • Frame and Page Navigation

Overview for Windows Phone – MSDN

• Frame

• Is where pages are rendered.

• Exposes properties from a hosted page such as screen orientation.

• Exposes NavigationService.

• Reserves space for Application Bar and Status Bar.

Page 7: Fundamental Concepts for Building a Windows Phone 7 App

Application Page Model • Application Page Model for

Windows Phone – MSDN

• A Page is a user-recognizable collection of persistent state.

• A Screen is a something such as a pop-up window, dialog box or splash screen and does not contain memorable content.

• Pages can communicate through simple Querystrings. Complex objects need to be persisted and restored from page to page.

• Need to manage Backstack to make sure user navigation makes sense.

• NavigationService.BackStack

• NavigationService.RemoveBackEntry

Page 8: Fundamental Concepts for Building a Windows Phone 7 App

Orientation

How to: Handle Orientation Changes on Windows Phone – MSDN

Like most mobile devices Windows Phone supports both Portrait and Landscape orientations.

You need to set the supported orientation(s) on each page by setting the Orientation property through XAML or Code.

There are different strategies to handle orientations. Some out of the box support if you use Stack Panels and Scroll Views.

Alternatively you can handle the OrientationChanged event and adjust your layout accordingly.

Page 9: Fundamental Concepts for Building a Windows Phone 7 App

Windows Phone Project Types

DEMO

Page 10: Fundamental Concepts for Building a Windows Phone 7 App

Page Layout

Grid

StackPanel

Canvas

WrapPanel

Part of Silverlight Toolkit

Others

Page 11: Fundamental Concepts for Building a Windows Phone 7 App

Grid

Default container used when using a basic Phone template.

You define Columns and Rows to place other controls into.

Cells can be fixed size or have the ability to float.

Auto – Adjusts the cells size based on the content contained with-in.

Star Sizing (*) – Indicates that the cell should take the remaining space available in the row or column. If you have multiple cells with asterisks you can proceed the asterisk with a number (example 3*) to weight each one against the others.

Page 12: Fundamental Concepts for Building a Windows Phone 7 App

StackPanel

Controls are stacked upon each other.

Can set the Orientation property to either Horizontal or Vertical.

If the StackPanel contains more items than can be displayed in the view port they will be cropped.

Can wrap the StackPanel with a ScrollViewer to allow the user to scroll to see items outside the view port.

Page 13: Fundamental Concepts for Building a Windows Phone 7 App

Canvas

Coordinate based layout using offests, Left and Top, to position controls with-in the Canvas.

Position 0,0 is Upper Left corner, unless of course your FlowDirection property is set to RightToLeft.

Page 14: Fundamental Concepts for Building a Windows Phone 7 App

WrapPanel

Works like the StackPanel except when items reach the edge they won’t be cropped but instead wrapped to the next row or column (depending on the Orientation).

Page 15: Fundamental Concepts for Building a Windows Phone 7 App

Dependency Properties

Dependency Property Overview – MSDN

Applies to WPF and Silverlight.

A special property that uses a dictionary as a backing store that keeps track of values across all instances of a particular type.

A hierarchical relationship is built between the values.

Reduces memory foot print.

Mechanism built in to notify when a value is changed.

Page 16: Fundamental Concepts for Building a Windows Phone 7 App

Dependency Properties – Cont.

They are often used in XAML and provide a similar experience to how CSS works for HTML.

Allows you to specify a value at different levels:

Application Resources

Page/User Control Resources

Control Resources

Direct Properties on the Control

Page 17: Fundamental Concepts for Building a Windows Phone 7 App

Attached Properties

Attached Properties Overview – MSDN

Are typically a special type of Dependency Property.

Are used as a way to relate controls to each other.

You essential are registering the control you want to Attach using the property on the control you want to attach to.

Page 18: Fundamental Concepts for Building a Windows Phone 7 App

Setting Properties in XAML

There are two ways to set properties in XAML:

Attributes

Elements

Attributes can only accept string input.

Certain Attributes have Type converters that can take structured strings, example being Margin where you define the thickness of each side of the box separated by commas.

There are certain properties whose values can’t be expressed with a simple textual value. In these cases you can set them using the Element syntax. All properties can be set this way but if you can set them using the Attribute syntax there isn’t much value in using the Element syntax.

Page 19: Fundamental Concepts for Building a Windows Phone 7 App

Data Storage

Isolated Storage Overview for Windows Phone – MSDN

Three main ways to store data:

Settings: Store data as key/value pairs by using the IsolatedStorageSettings class.

Files and folders: Store files and folders by using the IsolatedStorageFile class.

Relational data: Store relational data in a local database by using LINQ to SQL.

Page 20: Fundamental Concepts for Building a Windows Phone 7 App

Relational Data

Uses SQL Server Compact Edition

Use LINQ to SQL to work with database.

Scheme is managed through decorating classes with special Attributes.

Table

Column

Assocation

Page 21: Fundamental Concepts for Building a Windows Phone 7 App

Relational Data – Cont.

Adding a version column to your tables significantly improves update performance.

If you plan to do read-only queries, after creating the DataContext set the ObjectTrackingEnabled property to false. This will improve performance as changes to objects wont be tracked.

Page 22: Fundamental Concepts for Building a Windows Phone 7 App

Relational Data – Versioning

You check your database version using the DatabaseSchemeUpdater class.

You also use this class to submit scheme changes.

Can only make Additive changes.

If you need to make complex scheme changes you need to create a new database and migrate the data from the old scheme to the new scheme.

Refer to Changing the Database Scheme section in this link for examples.

Page 23: Fundamental Concepts for Building a Windows Phone 7 App

Relational Data – Shipping DB

How to: Deploy a Reference Database with a Windows Phone Application – MSDN

In order to prepopulate a database with data you can either insert the data when the app starts or build a separate app to generate the database scheme and populate it with data.

Once populated you Use the Isolated Storage Explorer Tool to extract the database file from your device or emulator.

You add the DB as an existing item to your project and mark its Build Action to Content under the File Properties.

When deployed the file will live in the Reference Storage on the device in a Read-Only state. Must copy to Isolated Storage if you want to modify scheme or data.

Page 25: Fundamental Concepts for Building a Windows Phone 7 App

Device Theme Settings

Themes for Windows Phone – MSDN

When your app loads it takes a snapshot of the curremt Theme that is setup for the device.

Background

Accent Color

Make sure to test your app by changing these Theme settings to make sure you app looks ok. Particularly the Background colors.

To apply the Accent Color in XAML you use the "{StaticResource PhoneAccentBrush}"

In code you use (Color)Application.Current.Resources["PhoneAccentColor"]

To determine the Background setting from code you use:

(Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible

Page 26: Fundamental Concepts for Building a Windows Phone 7 App

Tips, Trick, & Mango

Hitting the Break key will enable the PC Keyboard in the Emulator.

Mango added some new Advanced Features to the Emulator.

Accelerometer

Location (Map)

Screenshots

There’s a way to enable more than one Emulator.

Long Press of Back button will bring up Application Switching.

Only 30 Apps can register push notifications at one time.

Page 27: Fundamental Concepts for Building a Windows Phone 7 App

Tips, Trick, & Mango – Cont.

You can test Tombstoning by going into the Projects Properties -> Debug tab and checking the box there.

A new menu item under Debug called Windows Phone Performance Analysis.

The WMAppManifest.xml file must contain a request for each Capability it needs access to by adding an entry into the Capabilities element.

Things such as Contacts, Locations, Appointments, etc.

By Default all capabilities are added, remove the items you don’t need.

Page 28: Fundamental Concepts for Building a Windows Phone 7 App

Tips, Trick, & Mango – Cont.

Mango added support for a Front and Back Live Tile.

In general, Tiles flip at regular intervals with each visible tile having a different 'start' time. (...because it looks better than all tiles flipping at the same time.)

Also, Tile flipping is suspended when the phone enters User Idle state, to save battery life, but will restart once the user starts using the phone again.

Live Tiles and Toaster notifications can now Deep Link into the app.

Can go to a specific page using Querystirng parameters.

You can now create multiple Live Tiles per App using this technique.

For Example, Pinning individual People on your Start Page.

Page 30: Fundamental Concepts for Building a Windows Phone 7 App

Tips, Trick, & Mango – Cont.

Visual Studio has a Market Place Test Kit that allows you to verify your App is Ready for submission.

In VS goto Project -> Open Market Place Test Kit

It helps make sure you have all your App Details setup.

Can run through the same Automated Tests the MS runs on their end.

Can also run through their Manual Test too.

Passing these tests will greatly improve your chance of getting your app approved. You can resolve the majority of the issues and minimize the back and forth overhead.

Page 31: Fundamental Concepts for Building a Windows Phone 7 App

App Submission

100 free app submissions a year.

Failed submissions and updates count towards this number.

$20 to increase the limit.

Paid apps can have a trial version.

No need for a Lite version.

API in code for checking this mode to branch your logic.

Can do beta testing with up to 100 testers.

Private link sent via e-mail.

90 days to test and provide feedback.


Recommended