SlideShare a Scribd company logo
1 of 66
Oliver Scheer
Senior Technical Evangelist
Microsoft Deutschland
http://the-oliver.com
Building Windows Phone
Applications
Agenda
Designing Windows Phone Applications
This module
follows on from the
previous, in which
we go through the
essential
knowledge you
need to build an
application
In this module:
ā€¢ Page navigation
ā€¢ Application Bar
ā€¢ Handling Page Orientation Changes
ā€¢ Handling Different Screen Resolutions
ā€¢ Localization
ā€¢ Windows Phone Toolkit
ā€¢ Page Transitions
Page Navigation
ā€¢ Frame
ā€¢ Top-level container control
ā€¢ PhoneApplicationFrame class
ā€¢ Contains the page control and system
elements such as system tray and
application bar
ā€¢ Page
ā€¢ Fills entire content region of the frame
ā€¢ PhoneApplicationPage-derived class
ā€¢ Contains a title
ā€¢ Optionally surfaces its own application bar
Frame and Page
Page Navigation
ā€¢XAML apps on Windows Phone use a
page-based navigation model
ā€¢ Similar to web page model
ā€¢ Each page identified by a URI
ā€¢ Each page is essentially stateless
private void HyperlinkButton_Click_1(
object sender, RoutedEventArgs e)
{
NavigationService.Navigate(
new Uri("/SecondPage.xaml", UriKind.Relative));
}
Navigating Back
ā€¢ Application can provide controls to navigate back
to preceding page
ā€¢ The hardware Back key will also navigate back to
preceding page
ā€¢ No code required ā€“ built-in behaviour
private void Button_Click_1(
object sender, RoutedEventArgs e)
{
NavigationService.GoBack();
}
Overriding Back Key
ā€¢ May need to override Back hardware key if ā€˜back to previous pageā€™ is not logical behaviour
ā€¢ For example, when displaying a popup panel
ā€¢ User would expect Back key to close the panel,
not the page
Overriding the Back Key
8
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
ā€¦
shell:SystemTray.IsVisible="True"
BackKeyPress="PhoneApplicationPage_BackKeyPress">
In code:
private void PhoneApplicationPage_BackKeyPress(object sender,
System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; // Tell system we've handled it
// Hide the popup...
...
}
Passing Data Between Pages
ā€¢ Can pass string data between pages using query strings
ā€¢ On destination page
private void passParam_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=" + textBox1.Text, UriKind.Relative));
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string querystringvalue = "";
if (NavigationContext.QueryString.TryGetValue("msg", out querystringvalue))
textBlock1.Text = querystringvalue;
}
Passing Objects Between Pages
ā€¢ Often, you will pass a data object from one page to another
ā€¢ E.g., user selects an item in a list and navigates to a Details
page
ā€¢ One solution is to store your ViewModel (that is, data)
in your App class
ā€¢ Global to whole application
ā€¢ Pass the ID of the selected item in query string
// Navigate to the new page
NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" +
(MainLongListSelector.SelectedItem as ItemViewModel).ID, UriKind.Relative));
Handling Non Linear Navigation
ā€¢ Design your app navigation strategy carefully!
ā€¢ If you navigate from ā€˜third pageā€™ to ā€˜main pageā€™ and
your user then presses the Back key, what happens?
ā€¢ User expects app to exit
ā€¢ App actually navigates back to Third Page
ā€¢ Solution for Windows Phone 7.0 was complex code to
handle back navigation correctly, or the Non-Linear
Navigation Recipe library from AppHub
ā€¢ Windows Phone APIs:
ā€¢ NavigationService.RemoveBackEntry()
11
NavigationService.RemoveBackEntry()
ā€¢ When ā€˜Third Pageā€™ navigates back to MainPage, put a marker in the query string
ā€¢ In OnNavigatedTo() in MainPage, look for the marker and if present, remove the ā€˜ Third Pageā€™,
ā€˜SecondPageā€™ and original instance of ā€˜MainPageā€™ from the navigation history stack
12
NavigationService.Navigate(new Uri("/MainPage.xaml?homeFromThird=true", UriKind.Relative));
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New
&& NavigationContext.QueryString.ContainsKey("homeFromThird"))
{
NavigationService.RemoveBackEntry(); // Remove ThirdPage
NavigationService.RemoveBackEntry(); // Remove SecondPage
NavigationService.RemoveBackEntry(); // Remove original MainPage
}
base.OnNavigatedTo(e);
}
Demo 1: Page
Navigation
13
ApplicationBar
Application Chrome System Tray
and Application Bar
Donā€™t fill all 4 slots if not needed
Use the ApplicationBar instead of creating
your own menu system
Up to 4 buttons plus optional menu
Swipe up the bar to bring up the menu
Swipe up the bar to bring up the menu
ApplicationBar
ApplicationBar in Xaml
17
<phone:PhoneApplicationPage
x:Class="CRMapp.MainPageā€œ
ā€¦>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar x:Name="AppBar" Opacity="1.0" IsMenuEnabled="True">
<shell:ApplicationBar.Buttons>
<shell:ApplicationBarIconButton x:Name="NewContactButton" IconUri="Images/appbar.new.rest.png"
Text="New" Click="NewContactButton_Click"/>
<shell:ApplicationBarIconButton x:Name="SearchButton" IconUri="Images/appbar.feature.search.rest.png"
Text="Find" Click="SearchButton_Click"/>
</shell:ApplicationBar.Buttons>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem x:Name="GenerateMenuItem" Text="Generate Data"
Click="GenerateMenuItem_Click" />
<shell:ApplicationBarMenuItem x:Name="ClearMenuItem" Text="Clear Data"
Click="ClearMenuItem_Click" />
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>
ApplicationBar and Landscape
ApplicationBarpaints on side of
screen in landscape
Has built-in animation when
page switches orientation
If Application Bar opacity is less than 1, displayed
page will be the size of the screen Application Bar
overlays screen content
If Opacity is 1, displayed page is resized to the area
of the screen not covered by the Application Bar
ApplicationBar Opacity
19
ApplicationBar Design in Blend ā€“ and now in VS Too!
Demo 2: Designing
an ApplicationBar
21
Handling Screen
Orientation Changes
Phone UI Design ā€“ Orientation
ā€¢ This application does not work in landscape mode at the moment
ā€¢ Not all applications do, or need to
ā€¢ You can configure applications to support portrait or landscape
23
New Device Tab in Visual Studio 2012
ā€¢ View Designer in Portrait or Landscape
3/17/201424
Selecting Orientations
ā€¢ A XAML property for the phone application page lets you select the orientation options
available
ā€¢ Your application can bind to an event which is fired when the orientation changes
25
SupportedOrientations="Portrait"
SupportedOrientations="PortraitOrLandscape"
Layout May Need Altering
3/17/201426
Layout unaltered
Layout optimised for
landscape
Using a Grid to Aid Landscape Layout
ā€¢ In the Grid, the second column is unused in Portrait
27
<phone:PivotItem Header="recipe">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="240"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
...
</Grid>
Row 0
Row 1
Row 2
Row 3
Column 0
Move Elements in Landscape Layout
ā€¢ In Landscape, the recipe description moves into the second row and the second column and
the third row of the grid is now unused. Since that rowā€™s Height is ā€œ*ā€, it shrinks to zero.
28
<phone:PivotItem Header="recipe">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="240"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
...
</Grid>
Row 0
Row 1
Row 2
Row 3
Column 0 Column 1
Moving Elements
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
if (this.Orientation == PageOrientation.LandscapeLeft || this.Orientation ==
PageOrientation.LandscapeRight)
{
DirectionsScrollViewer.SetValue(Grid.RowProperty, 1);
DirectionsScrollViewer.SetValue(Grid.ColumnProperty, 1);
}
else
{
DirectionsScrollViewer.SetValue(Grid.RowProperty, 2);
DirectionsScrollViewer.SetValue(Grid.ColumnProperty, 0);
}
}
3/17/201429
Demo 4:
Orientation Handling
Supporting Multiple
Screen Resolutions
3 Screen Resolutions
WVGA
800 x 480
15:9
WXGA
1280 x 768
15:9
720p
1280 x 720
16:9
ā€¢ Well, Noā€¦
ā€¢ As developers, we work with device independent pixels
ā€¢ OS applies a scale factor to the actual resolution
So I Have to Do Three Different UIs?
3/17/2014Microsoft confidential33
Resolution Aspect ratio Scale Factor Scaled resolution
WVGA 800 x 480 15:9 1.0x scale 800 x 480
WXGA 1280 x 768 15:9 1.6x scale 800 x 480
720p 1280 x 720 16:9
1.5x scale, 80 pixels
taller (53 pixels, before
scaling)
853 x 480
Scaled Resolutions
WVGA WXGA 720p
800
800
853
480
480
480
ā€¢ Set Grid Row Height to ā€œAutoā€ to size
according to the controls placed within it
ā€¢ Set Grid Row Height to ā€œ*ā€ to take up all the
rest of the space
ā€¢ If you size multiple rows using ā€œ*ā€, available
space is divided up evenly between them
Use ā€œAutoā€ and ā€œ*ā€ on Grid Rows To Ensure Good Layout
3/17/2014Microsoft confidential35
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="240"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
...
</Grid>
Adaptive Layout Using Grid
3/17/2014Microsoft confidential36
WVGA 720p
Image height sized
explicitly at 240px
Bottom row is ā€œAutoā€ so
sized to hold a TextBlock
Directions row is ā€œ*ā€ so
gets everything thatā€™s left
ā€“ ends up taller on 720p
ā€¢ In most cases, you should supply images targeting the WXGA (1280 x 768) screen
ā€¢ WXGA assets are of the highest quality
ā€¢ Will automatically scale down on WVGA phones
ā€¢ Still look great on 720p (1280 x 720)
ā€¢ If you want, you can include images at each of the three resolutions in your project
ā€¢ E.g. MyImage.wvga.png, MyImage.wxga.png and MyImage.720p.png
ā€¢ At runtime, get Application.Current.Host.Content.ScaleFactor to determine the
resolution of the screen on the current phone, returns 100 for WVGA, 160 for WXGA and 150 for
720p
ā€¢ Write code to load image at runtime appropriate for the current screen resolution
Images
3/17/2014Microsoft confidential37
ā€¢ To add a splash screen to your project suitable for all resolutions, add a file as content
called SplashScreenImage.jpg at 768 x 1280 resolution
ā€¢ The framework automatically scales it to the correct size on different resolution screens
ā€¢ If you want to provide pixel-perfect splash screens for all resolutions, add images with the
following names:
ā€¢ SplashScreenImage.Screen-WVGA.jpg
ā€¢ SplashScreenImage.Screen-WXGA.jpg
ā€¢ SplashScreenImage.Screen-720p.jpg
ā€¢ In addition to these images, you must still include the default SplashScreenImage.jpg file
Splash Screens
3/17/2014Microsoft confidential38
ā€¢ You must supply app icon and tile images sized for WXGA
ā€¢ The framework automatically scales to the correct size for WVGA and 720p
App Icon and Tiles
3/17/2014Microsoft confidential39
Tile size WXGA
Application Icon 100 Ɨ 100
Small 159 Ɨ 159
Medium 336 Ɨ 336
Large 691 Ɨ 336
Demo 4: Screen
Resolutions
40
Introduction to
Localization
ā€¢ Windows Phone 8 supports 50 display languages (shipped with the
phone depending on market and country/region) and selectable by
the user on the language+region section of the Settings page
ā€¢ Windows Phone 7.1 supported only 24
ā€¢ Windows Phone 8 allows you to build apps that read from right to
left
Windows Phone 8 Language Support
3/17/2014
ā€¢ Every new project you create in Visual Studio 2012 has a class
included called LocalizedStrings
ā€¢ Simply provides programmatic access to resources
ā€¢ An instance of this is create in App.xaml in the Application Resources
with the key LocalizedStrings
ā€¢ Every new project also includes a resources file:
ResourcesAppResources.resx
ā€¢ Some strings already defined in here
ā€¢ Create all your string literals in here to support localization
ā€¢ All new projects also included commented-out code in
MainPage.xaml.cs to setup a localized Application Bar
New Project Templates Have Localization Support Built In
3/17/2014
ā€¢ Databind the Text property of your
TextBlock and other controls to the
StaticResource with a key of
LocalizedStrings
ā€¢ That is an instance of the
LocalizedStrings class
ā€¢ It provides access to string
resources
Accessing String Resources from XAML
3/17/2014Microsoft confidential44
ā€¢ Double-click project properties to open the Properties editor
ā€¢ On the Application tab
ā€¢ Check each of the
languages your app
will support
ā€¢ Save the Project Properties
ā€¢ Visual Studio creates new
AppResources files for each
selected language/culture
Add Support for Additional Languages
3/17/2014Microsoft confidential45
ā€¢ Visual Studio adds a resource file for each additional language that the app will support.
Each resource file is named using the correct culture/language name, as described in
Culture and language support for Windows Phone in the documentation
ā€¢ For example:
ā€¢ For the culture Spanish (Spain), file is AppResources.es-ES.resx.
ā€¢ For the culture German (Germany), file is AppResources.de-DE.resx.
ā€¢ Supply appropriate translations in each resource file
Translate the Additional Languages Resource Files
3/17/2014Microsoft confidential46
ā€¢ Double-click WMAppManifest.xml to open the manifest editor
ā€¢ On the Packaging tab
ā€¢ Set the Default Language
to the language of your
default resources
ā€¢ This identifies the language of the
strings in the default resources file.
For example, if the strings in the
default resources file are English
(United Kingdom) language strings,
you would select English (United Kingdom) as the Neutral Language for the project
Define the Default Language
3/17/2014Microsoft confidential47
Demo 5:
Localization
The Windows Phone
Toolkit
Windows Phone Toolkit
ā€¢ A product of the Microsoft Windows Phone team
ā€¢ Formerly known as the ā€˜Silverlight Toolkitā€™
ā€¢ The Windows Phone Toolkit adds new functionality ā€˜out of bandā€™ from the official product
control set
ā€¢ Includes full open source code, samples, documentation, and design-time support for controls
for Windows Phone
ā€¢ Refresh every three months or so
ā€¢ Bug fixes
ā€¢ New controls
50
How to Get the Windows Phone Toolkit
ā€¢ http://phone.codeplex.com
ā€¢ Get source code, including the
sample application
ā€¢ No MSI! ā€“ Install binaries from
NuGet only
NuGet
ā€¢ Package management system for .NET
ā€¢ Simplifies incorporating third-party libraries
ā€¢ Developer focused
ā€¢ Free, open source
ā€¢ NuGet client is included in Visual
Studio 2012 ā€“ including Express Editions!
ā€¢ Use NuGet to add libraries such as
the Windows Phone Toolkit to projects
Controls in the
Windows Phone
Toolkit
ContextMenu
DatePicker and TimePicker
55
ToggleSwitch
56
WrapPanel
57
ListPicker
ā€¢ WP7 ComboBox
ā€¢ Dropdown list for small number
of items
ā€¢ Full screen selector for longer lists
ā€¦And Many More
ā€¢ Custom MessageBox
ā€¢ Rating control
ā€¢ AutoCompleteBox
ā€¢ ExpanderView
ā€¢ HubTile
ā€¢ ā€¦moreā€¦
ā€¢ Download the source from http://Silverlight.codeplex.com, build the sample application
and deploy to emulator or device
3/17/201459
Page Transitions
and TiltEffect
Page Transitions
ā€¢ Easy way to add page transitions to your app similar to those in
the built-in apps
ā€¢ Different transitions are included
ā€¢ Roll, Swivel, Rotate, Slide and Turnstile
ā€¢ Start by using the TransitionFrame control from the Windows
Phone Toolkit instead of the default PhoneApplicationFrame
ā€¢ Set in InitializePhoneApplication() method in App.Xaml.cs:
Enabling Transitions on a Page
ā€¢ Declare namespace for Windows Phone Toolkit assembly
ā€¢ Under <phone:PhoneApplicationPage> root element, add transition you want
TiltEffect
ā€¢ Add additional visual feedback for control interaction
ā€¢ Instead of simple states such as Pressed or Unpressed, controls with TiltEffect enabled
provide motion during manipulation
ā€¢ For example, Button has a subtle 3D effect and appears to move into the page when
pressed and bounce back again when released
ā€¢ Easy to enable TiltEffect for all controls on a page
ā€¢ Also can apply to individual controls
Demo 6:
Page Transitions
and TiltEffect
64
Review
ā€¢ Navigation to pages is performed on the basis of a URI (Uniform Resource Indicator) values
ā€¢ The back button normally navigates back to the previous page, but this can be overridden
ā€¢ The URI can contain a query string to pass contextual string data
ā€¢ Support for Localization is incorporated into the project templates
ā€¢ Supporting different screen resolutions is simplified because they are scaled to a near-identical
effective resolution.
ā€¢ Supply images scaled for WXGA and they will be scaled down automatically for lower screen
resolutions.
ā€¢ The Windows Phone Toolkit is an out of band method for Microsoft to release additional tools and
libraries outside of Visual Studio release cycles
ā€¢ http://silverlight.codeplex.com
ā€¢ The toolkit includes Page transitions and TiltEffect with which you can add common animations to your
applications
The information herein is for informational
purposes only an represents the current view of
Microsoft Corporation as of the date of this
presentation. Because Microsoft must respond
to changing market conditions, it should not be
interpreted to be a commitment on the part of
Microsoft, and Microsoft cannot guarantee the
accuracy of any information provided after the
date of this presentation.
Ā© 2012 Microsoft Corporation.
All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION
IN THIS PRESENTATION.

More Related Content

Similar to Windows Phone 8 - 3 Building WP8 Applications

03.Controls in Windows Phone
03.Controls in Windows Phone03.Controls in Windows Phone
03.Controls in Windows PhoneNguyen Tuan
Ā 
User experience and interactions design
User experience and interactions design User experience and interactions design
User experience and interactions design Rakesh Jha
Ā 
Oracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptxOracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptxLuc Bors
Ā 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...Akira Hatsune
Ā 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 seriesopenbala
Ā 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
Ā 
Lecture 2 Styling and Layout in React Native.pptx
Lecture 2 Styling and Layout in React Native.pptxLecture 2 Styling and Layout in React Native.pptx
Lecture 2 Styling and Layout in React Native.pptxGevitaChinnaiah
Ā 
02.Designing Windows Phone Application
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone ApplicationNguyen Tuan
Ā 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android AppsGil Irizarry
Ā 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of XcodeDhaval Kaneria
Ā 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
Ā 
Silverlight week2
Silverlight week2Silverlight week2
Silverlight week2iedotnetug
Ā 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScriptGary Yeh
Ā 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentReto Meier
Ā 
WPF (Windows Presentation Foundation Unit 01)
WPF (Windows Presentation Foundation Unit 01)WPF (Windows Presentation Foundation Unit 01)
WPF (Windows Presentation Foundation Unit 01)Prashanth Shivakumar
Ā 
Application Development - Overview on Android OS
Application Development - Overview on Android OSApplication Development - Overview on Android OS
Application Development - Overview on Android OSPankaj Maheshwari
Ā 

Similar to Windows Phone 8 - 3 Building WP8 Applications (20)

03.Controls in Windows Phone
03.Controls in Windows Phone03.Controls in Windows Phone
03.Controls in Windows Phone
Ā 
User experience and interactions design
User experience and interactions design User experience and interactions design
User experience and interactions design
Ā 
Oracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptxOracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptx
Ā 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
Ā 
Best android classes in mumbai
Best android classes in mumbaiBest android classes in mumbai
Best android classes in mumbai
Ā 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 series
Ā 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
Ā 
Lecture 2 Styling and Layout in React Native.pptx
Lecture 2 Styling and Layout in React Native.pptxLecture 2 Styling and Layout in React Native.pptx
Lecture 2 Styling and Layout in React Native.pptx
Ā 
##dd12 sviluppo mobile XPages
##dd12 sviluppo mobile XPages##dd12 sviluppo mobile XPages
##dd12 sviluppo mobile XPages
Ā 
Android by Swecha
Android by SwechaAndroid by Swecha
Android by Swecha
Ā 
Session 5#
Session 5#Session 5#
Session 5#
Ā 
02.Designing Windows Phone Application
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone Application
Ā 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
Ā 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
Ā 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
Ā 
Silverlight week2
Silverlight week2Silverlight week2
Silverlight week2
Ā 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScript
Ā 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android Development
Ā 
WPF (Windows Presentation Foundation Unit 01)
WPF (Windows Presentation Foundation Unit 01)WPF (Windows Presentation Foundation Unit 01)
WPF (Windows Presentation Foundation Unit 01)
Ā 
Application Development - Overview on Android OS
Application Development - Overview on Android OSApplication Development - Overview on Android OS
Application Development - Overview on Android OS
Ā 

More from Oliver Scheer

Windows Phone 8 - 17 The Windows Phone Store
Windows Phone 8 - 17 The Windows Phone StoreWindows Phone 8 - 17 The Windows Phone Store
Windows Phone 8 - 17 The Windows Phone StoreOliver Scheer
Ā 
Windows Phone 8 - 14 Using Speech
Windows Phone 8 - 14 Using SpeechWindows Phone 8 - 14 Using Speech
Windows Phone 8 - 14 Using SpeechOliver Scheer
Ā 
Windows Phone 8 - 12 Network Communication
Windows Phone 8 - 12 Network CommunicationWindows Phone 8 - 12 Network Communication
Windows Phone 8 - 12 Network CommunicationOliver Scheer
Ā 
Windows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App CommunicationWindows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App CommunicationOliver Scheer
Ā 
Windows Phone 8 - 10 Using Phone Resources
Windows Phone 8 - 10 Using Phone ResourcesWindows Phone 8 - 10 Using Phone Resources
Windows Phone 8 - 10 Using Phone ResourcesOliver Scheer
Ā 
Windows Phone 8 - 9 Push Notifications
Windows Phone 8 - 9 Push NotificationsWindows Phone 8 - 9 Push Notifications
Windows Phone 8 - 9 Push NotificationsOliver Scheer
Ā 
Windows Phone 8 - 8 Tiles and Lock Screen Notifications
Windows Phone 8 - 8 Tiles and Lock Screen NotificationsWindows Phone 8 - 8 Tiles and Lock Screen Notifications
Windows Phone 8 - 8 Tiles and Lock Screen NotificationsOliver Scheer
Ā 
Windows Phone 8 - 7 Local Database
Windows Phone 8 - 7 Local DatabaseWindows Phone 8 - 7 Local Database
Windows Phone 8 - 7 Local DatabaseOliver Scheer
Ā 
Windows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageWindows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageOliver Scheer
Ā 
Windows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingWindows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingOliver Scheer
Ā 
Windows Phone 8 - 1 Introducing Windows Phone 8 Development
Windows Phone 8 - 1 Introducing Windows Phone 8 DevelopmentWindows Phone 8 - 1 Introducing Windows Phone 8 Development
Windows Phone 8 - 1 Introducing Windows Phone 8 DevelopmentOliver Scheer
Ā 
Windows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageWindows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageOliver Scheer
Ā 

More from Oliver Scheer (12)

Windows Phone 8 - 17 The Windows Phone Store
Windows Phone 8 - 17 The Windows Phone StoreWindows Phone 8 - 17 The Windows Phone Store
Windows Phone 8 - 17 The Windows Phone Store
Ā 
Windows Phone 8 - 14 Using Speech
Windows Phone 8 - 14 Using SpeechWindows Phone 8 - 14 Using Speech
Windows Phone 8 - 14 Using Speech
Ā 
Windows Phone 8 - 12 Network Communication
Windows Phone 8 - 12 Network CommunicationWindows Phone 8 - 12 Network Communication
Windows Phone 8 - 12 Network Communication
Ā 
Windows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App CommunicationWindows Phone 8 - 11 App to App Communication
Windows Phone 8 - 11 App to App Communication
Ā 
Windows Phone 8 - 10 Using Phone Resources
Windows Phone 8 - 10 Using Phone ResourcesWindows Phone 8 - 10 Using Phone Resources
Windows Phone 8 - 10 Using Phone Resources
Ā 
Windows Phone 8 - 9 Push Notifications
Windows Phone 8 - 9 Push NotificationsWindows Phone 8 - 9 Push Notifications
Windows Phone 8 - 9 Push Notifications
Ā 
Windows Phone 8 - 8 Tiles and Lock Screen Notifications
Windows Phone 8 - 8 Tiles and Lock Screen NotificationsWindows Phone 8 - 8 Tiles and Lock Screen Notifications
Windows Phone 8 - 8 Tiles and Lock Screen Notifications
Ā 
Windows Phone 8 - 7 Local Database
Windows Phone 8 - 7 Local DatabaseWindows Phone 8 - 7 Local Database
Windows Phone 8 - 7 Local Database
Ā 
Windows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageWindows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and Storage
Ā 
Windows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingWindows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async Programming
Ā 
Windows Phone 8 - 1 Introducing Windows Phone 8 Development
Windows Phone 8 - 1 Introducing Windows Phone 8 DevelopmentWindows Phone 8 - 1 Introducing Windows Phone 8 Development
Windows Phone 8 - 1 Introducing Windows Phone 8 Development
Ā 
Windows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and StorageWindows Phone 8 - 4 Files and Storage
Windows Phone 8 - 4 Files and Storage
Ā 

Recently uploaded

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
Ā 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
Ā 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
Ā 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
Ā 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
Ā 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
Ā 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
Ā 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĆŗjo
Ā 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
Ā 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
Ā 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
Ā 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
Ā 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
Ā 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
Ā 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
Ā 

Recently uploaded (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
Ā 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Ā 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
Ā 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
Ā 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
Ā 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
Ā 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Ā 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Ā 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
Ā 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Ā 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Ā 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Ā 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Ā 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
Ā 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Ā 

Windows Phone 8 - 3 Building WP8 Applications

  • 1. Oliver Scheer Senior Technical Evangelist Microsoft Deutschland http://the-oliver.com Building Windows Phone Applications
  • 2. Agenda Designing Windows Phone Applications This module follows on from the previous, in which we go through the essential knowledge you need to build an application In this module: ā€¢ Page navigation ā€¢ Application Bar ā€¢ Handling Page Orientation Changes ā€¢ Handling Different Screen Resolutions ā€¢ Localization ā€¢ Windows Phone Toolkit ā€¢ Page Transitions
  • 4. ā€¢ Frame ā€¢ Top-level container control ā€¢ PhoneApplicationFrame class ā€¢ Contains the page control and system elements such as system tray and application bar ā€¢ Page ā€¢ Fills entire content region of the frame ā€¢ PhoneApplicationPage-derived class ā€¢ Contains a title ā€¢ Optionally surfaces its own application bar Frame and Page
  • 5. Page Navigation ā€¢XAML apps on Windows Phone use a page-based navigation model ā€¢ Similar to web page model ā€¢ Each page identified by a URI ā€¢ Each page is essentially stateless private void HyperlinkButton_Click_1( object sender, RoutedEventArgs e) { NavigationService.Navigate( new Uri("/SecondPage.xaml", UriKind.Relative)); }
  • 6. Navigating Back ā€¢ Application can provide controls to navigate back to preceding page ā€¢ The hardware Back key will also navigate back to preceding page ā€¢ No code required ā€“ built-in behaviour private void Button_Click_1( object sender, RoutedEventArgs e) { NavigationService.GoBack(); }
  • 7. Overriding Back Key ā€¢ May need to override Back hardware key if ā€˜back to previous pageā€™ is not logical behaviour ā€¢ For example, when displaying a popup panel ā€¢ User would expect Back key to close the panel, not the page
  • 8. Overriding the Back Key 8 <phone:PhoneApplicationPage x:Class="PhoneApp1.MainPage" ā€¦ shell:SystemTray.IsVisible="True" BackKeyPress="PhoneApplicationPage_BackKeyPress"> In code: private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = true; // Tell system we've handled it // Hide the popup... ... }
  • 9. Passing Data Between Pages ā€¢ Can pass string data between pages using query strings ā€¢ On destination page private void passParam_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=" + textBox1.Text, UriKind.Relative)); } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); string querystringvalue = ""; if (NavigationContext.QueryString.TryGetValue("msg", out querystringvalue)) textBlock1.Text = querystringvalue; }
  • 10. Passing Objects Between Pages ā€¢ Often, you will pass a data object from one page to another ā€¢ E.g., user selects an item in a list and navigates to a Details page ā€¢ One solution is to store your ViewModel (that is, data) in your App class ā€¢ Global to whole application ā€¢ Pass the ID of the selected item in query string // Navigate to the new page NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + (MainLongListSelector.SelectedItem as ItemViewModel).ID, UriKind.Relative));
  • 11. Handling Non Linear Navigation ā€¢ Design your app navigation strategy carefully! ā€¢ If you navigate from ā€˜third pageā€™ to ā€˜main pageā€™ and your user then presses the Back key, what happens? ā€¢ User expects app to exit ā€¢ App actually navigates back to Third Page ā€¢ Solution for Windows Phone 7.0 was complex code to handle back navigation correctly, or the Non-Linear Navigation Recipe library from AppHub ā€¢ Windows Phone APIs: ā€¢ NavigationService.RemoveBackEntry() 11
  • 12. NavigationService.RemoveBackEntry() ā€¢ When ā€˜Third Pageā€™ navigates back to MainPage, put a marker in the query string ā€¢ In OnNavigatedTo() in MainPage, look for the marker and if present, remove the ā€˜ Third Pageā€™, ā€˜SecondPageā€™ and original instance of ā€˜MainPageā€™ from the navigation history stack 12 NavigationService.Navigate(new Uri("/MainPage.xaml?homeFromThird=true", UriKind.Relative)); protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New && NavigationContext.QueryString.ContainsKey("homeFromThird")) { NavigationService.RemoveBackEntry(); // Remove ThirdPage NavigationService.RemoveBackEntry(); // Remove SecondPage NavigationService.RemoveBackEntry(); // Remove original MainPage } base.OnNavigatedTo(e); }
  • 15. Application Chrome System Tray and Application Bar
  • 16. Donā€™t fill all 4 slots if not needed Use the ApplicationBar instead of creating your own menu system Up to 4 buttons plus optional menu Swipe up the bar to bring up the menu Swipe up the bar to bring up the menu ApplicationBar
  • 17. ApplicationBar in Xaml 17 <phone:PhoneApplicationPage x:Class="CRMapp.MainPageā€œ ā€¦> <phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar x:Name="AppBar" Opacity="1.0" IsMenuEnabled="True"> <shell:ApplicationBar.Buttons> <shell:ApplicationBarIconButton x:Name="NewContactButton" IconUri="Images/appbar.new.rest.png" Text="New" Click="NewContactButton_Click"/> <shell:ApplicationBarIconButton x:Name="SearchButton" IconUri="Images/appbar.feature.search.rest.png" Text="Find" Click="SearchButton_Click"/> </shell:ApplicationBar.Buttons> <shell:ApplicationBar.MenuItems> <shell:ApplicationBarMenuItem x:Name="GenerateMenuItem" Text="Generate Data" Click="GenerateMenuItem_Click" /> <shell:ApplicationBarMenuItem x:Name="ClearMenuItem" Text="Clear Data" Click="ClearMenuItem_Click" /> </shell:ApplicationBar.MenuItems> </shell:ApplicationBar> </phone:PhoneApplicationPage.ApplicationBar> </phone:PhoneApplicationPage>
  • 18. ApplicationBar and Landscape ApplicationBarpaints on side of screen in landscape Has built-in animation when page switches orientation
  • 19. If Application Bar opacity is less than 1, displayed page will be the size of the screen Application Bar overlays screen content If Opacity is 1, displayed page is resized to the area of the screen not covered by the Application Bar ApplicationBar Opacity 19
  • 20. ApplicationBar Design in Blend ā€“ and now in VS Too!
  • 21. Demo 2: Designing an ApplicationBar 21
  • 23. Phone UI Design ā€“ Orientation ā€¢ This application does not work in landscape mode at the moment ā€¢ Not all applications do, or need to ā€¢ You can configure applications to support portrait or landscape 23
  • 24. New Device Tab in Visual Studio 2012 ā€¢ View Designer in Portrait or Landscape 3/17/201424
  • 25. Selecting Orientations ā€¢ A XAML property for the phone application page lets you select the orientation options available ā€¢ Your application can bind to an event which is fired when the orientation changes 25 SupportedOrientations="Portrait" SupportedOrientations="PortraitOrLandscape"
  • 26. Layout May Need Altering 3/17/201426 Layout unaltered Layout optimised for landscape
  • 27. Using a Grid to Aid Landscape Layout ā€¢ In the Grid, the second column is unused in Portrait 27 <phone:PivotItem Header="recipe"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="240"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> ... </Grid> Row 0 Row 1 Row 2 Row 3 Column 0
  • 28. Move Elements in Landscape Layout ā€¢ In Landscape, the recipe description moves into the second row and the second column and the third row of the grid is now unused. Since that rowā€™s Height is ā€œ*ā€, it shrinks to zero. 28 <phone:PivotItem Header="recipe"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="240"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> ... </Grid> Row 0 Row 1 Row 2 Row 3 Column 0 Column 1
  • 29. Moving Elements private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { if (this.Orientation == PageOrientation.LandscapeLeft || this.Orientation == PageOrientation.LandscapeRight) { DirectionsScrollViewer.SetValue(Grid.RowProperty, 1); DirectionsScrollViewer.SetValue(Grid.ColumnProperty, 1); } else { DirectionsScrollViewer.SetValue(Grid.RowProperty, 2); DirectionsScrollViewer.SetValue(Grid.ColumnProperty, 0); } } 3/17/201429
  • 32. 3 Screen Resolutions WVGA 800 x 480 15:9 WXGA 1280 x 768 15:9 720p 1280 x 720 16:9
  • 33. ā€¢ Well, Noā€¦ ā€¢ As developers, we work with device independent pixels ā€¢ OS applies a scale factor to the actual resolution So I Have to Do Three Different UIs? 3/17/2014Microsoft confidential33 Resolution Aspect ratio Scale Factor Scaled resolution WVGA 800 x 480 15:9 1.0x scale 800 x 480 WXGA 1280 x 768 15:9 1.6x scale 800 x 480 720p 1280 x 720 16:9 1.5x scale, 80 pixels taller (53 pixels, before scaling) 853 x 480
  • 34. Scaled Resolutions WVGA WXGA 720p 800 800 853 480 480 480
  • 35. ā€¢ Set Grid Row Height to ā€œAutoā€ to size according to the controls placed within it ā€¢ Set Grid Row Height to ā€œ*ā€ to take up all the rest of the space ā€¢ If you size multiple rows using ā€œ*ā€, available space is divided up evenly between them Use ā€œAutoā€ and ā€œ*ā€ on Grid Rows To Ensure Good Layout 3/17/2014Microsoft confidential35 <Grid> <Grid.RowDefinitions> <RowDefinition Height="240"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> ... </Grid>
  • 36. Adaptive Layout Using Grid 3/17/2014Microsoft confidential36 WVGA 720p Image height sized explicitly at 240px Bottom row is ā€œAutoā€ so sized to hold a TextBlock Directions row is ā€œ*ā€ so gets everything thatā€™s left ā€“ ends up taller on 720p
  • 37. ā€¢ In most cases, you should supply images targeting the WXGA (1280 x 768) screen ā€¢ WXGA assets are of the highest quality ā€¢ Will automatically scale down on WVGA phones ā€¢ Still look great on 720p (1280 x 720) ā€¢ If you want, you can include images at each of the three resolutions in your project ā€¢ E.g. MyImage.wvga.png, MyImage.wxga.png and MyImage.720p.png ā€¢ At runtime, get Application.Current.Host.Content.ScaleFactor to determine the resolution of the screen on the current phone, returns 100 for WVGA, 160 for WXGA and 150 for 720p ā€¢ Write code to load image at runtime appropriate for the current screen resolution Images 3/17/2014Microsoft confidential37
  • 38. ā€¢ To add a splash screen to your project suitable for all resolutions, add a file as content called SplashScreenImage.jpg at 768 x 1280 resolution ā€¢ The framework automatically scales it to the correct size on different resolution screens ā€¢ If you want to provide pixel-perfect splash screens for all resolutions, add images with the following names: ā€¢ SplashScreenImage.Screen-WVGA.jpg ā€¢ SplashScreenImage.Screen-WXGA.jpg ā€¢ SplashScreenImage.Screen-720p.jpg ā€¢ In addition to these images, you must still include the default SplashScreenImage.jpg file Splash Screens 3/17/2014Microsoft confidential38
  • 39. ā€¢ You must supply app icon and tile images sized for WXGA ā€¢ The framework automatically scales to the correct size for WVGA and 720p App Icon and Tiles 3/17/2014Microsoft confidential39 Tile size WXGA Application Icon 100 Ɨ 100 Small 159 Ɨ 159 Medium 336 Ɨ 336 Large 691 Ɨ 336
  • 42. ā€¢ Windows Phone 8 supports 50 display languages (shipped with the phone depending on market and country/region) and selectable by the user on the language+region section of the Settings page ā€¢ Windows Phone 7.1 supported only 24 ā€¢ Windows Phone 8 allows you to build apps that read from right to left Windows Phone 8 Language Support 3/17/2014
  • 43. ā€¢ Every new project you create in Visual Studio 2012 has a class included called LocalizedStrings ā€¢ Simply provides programmatic access to resources ā€¢ An instance of this is create in App.xaml in the Application Resources with the key LocalizedStrings ā€¢ Every new project also includes a resources file: ResourcesAppResources.resx ā€¢ Some strings already defined in here ā€¢ Create all your string literals in here to support localization ā€¢ All new projects also included commented-out code in MainPage.xaml.cs to setup a localized Application Bar New Project Templates Have Localization Support Built In 3/17/2014
  • 44. ā€¢ Databind the Text property of your TextBlock and other controls to the StaticResource with a key of LocalizedStrings ā€¢ That is an instance of the LocalizedStrings class ā€¢ It provides access to string resources Accessing String Resources from XAML 3/17/2014Microsoft confidential44
  • 45. ā€¢ Double-click project properties to open the Properties editor ā€¢ On the Application tab ā€¢ Check each of the languages your app will support ā€¢ Save the Project Properties ā€¢ Visual Studio creates new AppResources files for each selected language/culture Add Support for Additional Languages 3/17/2014Microsoft confidential45
  • 46. ā€¢ Visual Studio adds a resource file for each additional language that the app will support. Each resource file is named using the correct culture/language name, as described in Culture and language support for Windows Phone in the documentation ā€¢ For example: ā€¢ For the culture Spanish (Spain), file is AppResources.es-ES.resx. ā€¢ For the culture German (Germany), file is AppResources.de-DE.resx. ā€¢ Supply appropriate translations in each resource file Translate the Additional Languages Resource Files 3/17/2014Microsoft confidential46
  • 47. ā€¢ Double-click WMAppManifest.xml to open the manifest editor ā€¢ On the Packaging tab ā€¢ Set the Default Language to the language of your default resources ā€¢ This identifies the language of the strings in the default resources file. For example, if the strings in the default resources file are English (United Kingdom) language strings, you would select English (United Kingdom) as the Neutral Language for the project Define the Default Language 3/17/2014Microsoft confidential47
  • 50. Windows Phone Toolkit ā€¢ A product of the Microsoft Windows Phone team ā€¢ Formerly known as the ā€˜Silverlight Toolkitā€™ ā€¢ The Windows Phone Toolkit adds new functionality ā€˜out of bandā€™ from the official product control set ā€¢ Includes full open source code, samples, documentation, and design-time support for controls for Windows Phone ā€¢ Refresh every three months or so ā€¢ Bug fixes ā€¢ New controls 50
  • 51. How to Get the Windows Phone Toolkit ā€¢ http://phone.codeplex.com ā€¢ Get source code, including the sample application ā€¢ No MSI! ā€“ Install binaries from NuGet only
  • 52. NuGet ā€¢ Package management system for .NET ā€¢ Simplifies incorporating third-party libraries ā€¢ Developer focused ā€¢ Free, open source ā€¢ NuGet client is included in Visual Studio 2012 ā€“ including Express Editions! ā€¢ Use NuGet to add libraries such as the Windows Phone Toolkit to projects
  • 53. Controls in the Windows Phone Toolkit
  • 58. ListPicker ā€¢ WP7 ComboBox ā€¢ Dropdown list for small number of items ā€¢ Full screen selector for longer lists
  • 59. ā€¦And Many More ā€¢ Custom MessageBox ā€¢ Rating control ā€¢ AutoCompleteBox ā€¢ ExpanderView ā€¢ HubTile ā€¢ ā€¦moreā€¦ ā€¢ Download the source from http://Silverlight.codeplex.com, build the sample application and deploy to emulator or device 3/17/201459
  • 61. Page Transitions ā€¢ Easy way to add page transitions to your app similar to those in the built-in apps ā€¢ Different transitions are included ā€¢ Roll, Swivel, Rotate, Slide and Turnstile ā€¢ Start by using the TransitionFrame control from the Windows Phone Toolkit instead of the default PhoneApplicationFrame ā€¢ Set in InitializePhoneApplication() method in App.Xaml.cs:
  • 62. Enabling Transitions on a Page ā€¢ Declare namespace for Windows Phone Toolkit assembly ā€¢ Under <phone:PhoneApplicationPage> root element, add transition you want
  • 63. TiltEffect ā€¢ Add additional visual feedback for control interaction ā€¢ Instead of simple states such as Pressed or Unpressed, controls with TiltEffect enabled provide motion during manipulation ā€¢ For example, Button has a subtle 3D effect and appears to move into the page when pressed and bounce back again when released ā€¢ Easy to enable TiltEffect for all controls on a page ā€¢ Also can apply to individual controls
  • 65. Review ā€¢ Navigation to pages is performed on the basis of a URI (Uniform Resource Indicator) values ā€¢ The back button normally navigates back to the previous page, but this can be overridden ā€¢ The URI can contain a query string to pass contextual string data ā€¢ Support for Localization is incorporated into the project templates ā€¢ Supporting different screen resolutions is simplified because they are scaled to a near-identical effective resolution. ā€¢ Supply images scaled for WXGA and they will be scaled down automatically for lower screen resolutions. ā€¢ The Windows Phone Toolkit is an out of band method for Microsoft to release additional tools and libraries outside of Visual Studio release cycles ā€¢ http://silverlight.codeplex.com ā€¢ The toolkit includes Page transitions and TiltEffect with which you can add common animations to your applications
  • 66. The information herein is for informational purposes only an represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. Ā© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.