SlideShare a Scribd company logo
1 of 65
Download to read offline
Building Windows Phone
Applications
Nguyen Tuan | Microsoft Certified Trainer
Agenda
• Page navigation
• Application Bar
• Page Orientation
• 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
NavigationApp
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
ApplicationBar paints 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
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
8/16/2014 24
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
8/16/2014 26
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);
}
}
8/16/2014 29
Demo
LandScape Orietation
Supporting Multiple
Screen Resolutions
Multiple Resolutions
Multiple Resolutions – Scaling & Touch
720p
720x1280
WVGA
480x800
• 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?
8/16/2014 34
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
8/16/2014 36
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="240"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
...
</Grid>
Adaptive Layout Using Grid
8/16/2014 37
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
8/16/2014 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
8/16/2014 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
8/16/2014 40
Tile size WXGA
Application Icon 100 × 100
Small 159 × 159
Medium 336 × 336
Large 691 × 336
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
Language Support
http://msdn.microsoft.com/en-
us/library/windowsphone/develop/ff637520(v=vs.105).aspx
• 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
8/16/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
8/16/2014 44
• 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
8/16/2014 45
• 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
8/16/2014 46
• 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
8/16/2014 47
Demo
AnimalSound
The Windows Phone Toolkit
WPToolkit
• 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 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
8/16/2014 59
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
PhoneToolkitSample
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

More Related Content

Viewers also liked

Psr An International Overview
Psr An International OverviewPsr An International Overview
Psr An International Overvieweuweben01
 
Skins presentation - media
Skins presentation - mediaSkins presentation - media
Skins presentation - mediasarahisaacs1992
 
Media Ideas Presentation
Media Ideas PresentationMedia Ideas Presentation
Media Ideas PresentationLolly91
 
İzmi̇t 4 Aralık 2014 Erol Köse Kitabının İmza Günündeyiz
İzmi̇t 4 Aralık 2014 Erol Köse Kitabının İmza Günündeyizİzmi̇t 4 Aralık 2014 Erol Köse Kitabının İmza Günündeyiz
İzmi̇t 4 Aralık 2014 Erol Köse Kitabının İmza Günündeyizaokutur
 
Mongara Csn kiruna temadag 111125 Anders Lindh
Mongara Csn kiruna temadag 111125 Anders LindhMongara Csn kiruna temadag 111125 Anders Lindh
Mongara Csn kiruna temadag 111125 Anders LindhMongara AB
 
Serap Mutlu Akbulut Korosu 1 Mart 2016 Konser Resimleri
Serap Mutlu Akbulut Korosu 1 Mart 2016 Konser ResimleriSerap Mutlu Akbulut Korosu 1 Mart 2016 Konser Resimleri
Serap Mutlu Akbulut Korosu 1 Mart 2016 Konser Resimleriaokutur
 
Business and Film preso medium length w saas mgt
Business and Film preso medium length w saas mgtBusiness and Film preso medium length w saas mgt
Business and Film preso medium length w saas mgtRipMedia Group,
 
Låt analysen driva Er digitala transformation!
Låt analysen driva Er digitala transformation!Låt analysen driva Er digitala transformation!
Låt analysen driva Er digitala transformation!Mattias Malmnäs
 
Как запустить рекламную кампанию?
Как запустить рекламную кампанию?Как запустить рекламную кампанию?
Как запустить рекламную кампанию?Ingria. Technopark St. Petersburg
 
08.Push Notifications
08.Push Notifications 08.Push Notifications
08.Push Notifications Nguyen Tuan
 

Viewers also liked (20)

Gov Out
Gov OutGov Out
Gov Out
 
Folleto Folder
Folleto FolderFolleto Folder
Folleto Folder
 
Ci 102
Ci 102Ci 102
Ci 102
 
Psr An International Overview
Psr An International OverviewPsr An International Overview
Psr An International Overview
 
Skins presentation - media
Skins presentation - mediaSkins presentation - media
Skins presentation - media
 
Media Ideas Presentation
Media Ideas PresentationMedia Ideas Presentation
Media Ideas Presentation
 
Cells
CellsCells
Cells
 
İzmi̇t 4 Aralık 2014 Erol Köse Kitabının İmza Günündeyiz
İzmi̇t 4 Aralık 2014 Erol Köse Kitabının İmza Günündeyizİzmi̇t 4 Aralık 2014 Erol Köse Kitabının İmza Günündeyiz
İzmi̇t 4 Aralık 2014 Erol Köse Kitabının İmza Günündeyiz
 
Mongara Csn kiruna temadag 111125 Anders Lindh
Mongara Csn kiruna temadag 111125 Anders LindhMongara Csn kiruna temadag 111125 Anders Lindh
Mongara Csn kiruna temadag 111125 Anders Lindh
 
Zebra
ZebraZebra
Zebra
 
Serap Mutlu Akbulut Korosu 1 Mart 2016 Konser Resimleri
Serap Mutlu Akbulut Korosu 1 Mart 2016 Konser ResimleriSerap Mutlu Akbulut Korosu 1 Mart 2016 Konser Resimleri
Serap Mutlu Akbulut Korosu 1 Mart 2016 Konser Resimleri
 
Business and Film preso medium length w saas mgt
Business and Film preso medium length w saas mgtBusiness and Film preso medium length w saas mgt
Business and Film preso medium length w saas mgt
 
UDV 2016 Final
UDV 2016 FinalUDV 2016 Final
UDV 2016 Final
 
Låt analysen driva Er digitala transformation!
Låt analysen driva Er digitala transformation!Låt analysen driva Er digitala transformation!
Låt analysen driva Er digitala transformation!
 
Как запустить рекламную кампанию?
Как запустить рекламную кампанию?Как запустить рекламную кампанию?
Как запустить рекламную кампанию?
 
Nile crocodile
Nile crocodileNile crocodile
Nile crocodile
 
Информационный вестник Июль 2012
Информационный вестник Июль 2012Информационный вестник Июль 2012
Информационный вестник Июль 2012
 
The camel
The camelThe camel
The camel
 
Impala
ImpalaImpala
Impala
 
08.Push Notifications
08.Push Notifications 08.Push Notifications
08.Push Notifications
 

Similar to 03.Controls in Windows Phone

Windows Phone 8 - 3 Building WP8 Applications
Windows Phone 8 - 3 Building WP8 ApplicationsWindows Phone 8 - 3 Building WP8 Applications
Windows Phone 8 - 3 Building WP8 ApplicationsOliver Scheer
 
User experience and interactions design
User experience and interactions design User experience and interactions design
User experience and interactions design Rakesh Jha
 
Windows Phone 8 - 2 Designing WP8 Applications
Windows Phone 8 - 2 Designing WP8 ApplicationsWindows Phone 8 - 2 Designing WP8 Applications
Windows Phone 8 - 2 Designing WP8 ApplicationsOliver Scheer
 
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
 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web DesignMike Wilcox
 
Designing and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsDesigning and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsTeddy Koornia
 
Windows phone 8 session 4
Windows phone 8 session 4Windows phone 8 session 4
Windows phone 8 session 4hitesh chothani
 
ADF Mobile : Best Practices for Developing Applications with Oracle ADF Mobile
ADF Mobile : Best Practices for Developing Applications with Oracle ADF MobileADF Mobile : Best Practices for Developing Applications with Oracle ADF Mobile
ADF Mobile : Best Practices for Developing Applications with Oracle ADF MobileLuc Bors
 
What you need to know about FEMAP v11.3
What you need to know about FEMAP v11.3What you need to know about FEMAP v11.3
What you need to know about FEMAP v11.3Aswin John
 
Windows phone app development overview
Windows phone app development overviewWindows phone app development overview
Windows phone app development overviewAlan Mendelevich
 
Advancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio
 
Win8 development lessons learned jayway
Win8 development lessons learned jaywayWin8 development lessons learned jayway
Win8 development lessons learned jaywayAndreas Hammar
 
Windows Phone Application development
Windows Phone Application developmentWindows Phone Application development
Windows Phone Application developmentvkalve
 
Creating Modern UI PowerBuilder Framework using native objects
Creating Modern UI PowerBuilder Framework using native objectsCreating Modern UI PowerBuilder Framework using native objects
Creating Modern UI PowerBuilder Framework using native objectszulmach .
 
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
 
Introduction to Android for Quality Engineers
Introduction to Android for Quality EngineersIntroduction to Android for Quality Engineers
Introduction to Android for Quality EngineersAhmed Faidy
 
Lecture14 abap on line
Lecture14 abap on lineLecture14 abap on line
Lecture14 abap on lineMilind Patil
 

Similar to 03.Controls in Windows Phone (20)

Windows Phone 8 - 3 Building WP8 Applications
Windows Phone 8 - 3 Building WP8 ApplicationsWindows Phone 8 - 3 Building WP8 Applications
Windows Phone 8 - 3 Building WP8 Applications
 
User experience and interactions design
User experience and interactions design User experience and interactions design
User experience and interactions design
 
Windows Phone 8 - 2 Designing WP8 Applications
Windows Phone 8 - 2 Designing WP8 ApplicationsWindows Phone 8 - 2 Designing WP8 Applications
Windows Phone 8 - 2 Designing WP8 Applications
 
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 ...
 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web Design
 
Prototyping + User Journeys
Prototyping + User JourneysPrototyping + User Journeys
Prototyping + User Journeys
 
Designing and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsDesigning and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tablets
 
Windows phone 8 session 4
Windows phone 8 session 4Windows phone 8 session 4
Windows phone 8 session 4
 
##dd12 sviluppo mobile XPages
##dd12 sviluppo mobile XPages##dd12 sviluppo mobile XPages
##dd12 sviluppo mobile XPages
 
ADF Mobile: Best Practices for Developing Applications with Oracle ADF Mobile...
ADF Mobile: Best Practices for Developing Applications with Oracle ADF Mobile...ADF Mobile: Best Practices for Developing Applications with Oracle ADF Mobile...
ADF Mobile: Best Practices for Developing Applications with Oracle ADF Mobile...
 
ADF Mobile : Best Practices for Developing Applications with Oracle ADF Mobile
ADF Mobile : Best Practices for Developing Applications with Oracle ADF MobileADF Mobile : Best Practices for Developing Applications with Oracle ADF Mobile
ADF Mobile : Best Practices for Developing Applications with Oracle ADF Mobile
 
What you need to know about FEMAP v11.3
What you need to know about FEMAP v11.3What you need to know about FEMAP v11.3
What you need to know about FEMAP v11.3
 
Windows phone app development overview
Windows phone app development overviewWindows phone app development overview
Windows phone app development overview
 
Advancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web DesignAdvancio, Inc. Academy: Responsive Web Design
Advancio, Inc. Academy: Responsive Web Design
 
Win8 development lessons learned jayway
Win8 development lessons learned jaywayWin8 development lessons learned jayway
Win8 development lessons learned jayway
 
Windows Phone Application development
Windows Phone Application developmentWindows Phone Application development
Windows Phone Application development
 
Creating Modern UI PowerBuilder Framework using native objects
Creating Modern UI PowerBuilder Framework using native objectsCreating Modern UI PowerBuilder Framework using native objects
Creating Modern UI PowerBuilder Framework using native objects
 
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
 
Introduction to Android for Quality Engineers
Introduction to Android for Quality EngineersIntroduction to Android for Quality Engineers
Introduction to Android for Quality Engineers
 
Lecture14 abap on line
Lecture14 abap on lineLecture14 abap on line
Lecture14 abap on line
 

More from Nguyen Tuan

07.Notifications & Reminder, Contact
07.Notifications & Reminder, Contact07.Notifications & Reminder, Contact
07.Notifications & Reminder, ContactNguyen Tuan
 
12.Maps and Location
12.Maps and Location12.Maps and Location
12.Maps and LocationNguyen Tuan
 
11.Open Data Protocol(ODATA)
11.Open Data Protocol(ODATA) 11.Open Data Protocol(ODATA)
11.Open Data Protocol(ODATA) Nguyen Tuan
 
10.Local Database & LINQ
10.Local Database & LINQ10.Local Database & LINQ
10.Local Database & LINQNguyen Tuan
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WPNguyen Tuan
 
13.Windows Phone Store
13.Windows Phone Store13.Windows Phone Store
13.Windows Phone StoreNguyen Tuan
 
06.Programming Media on Windows Phone
06.Programming Media on Windows Phone06.Programming Media on Windows Phone
06.Programming Media on Windows PhoneNguyen Tuan
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & AnimationNguyen Tuan
 
04.Navigation on Windows Phone
04.Navigation on Windows Phone04.Navigation on Windows Phone
04.Navigation on Windows PhoneNguyen Tuan
 
02.Designing Windows Phone Application
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone ApplicationNguyen Tuan
 

More from Nguyen Tuan (10)

07.Notifications & Reminder, Contact
07.Notifications & Reminder, Contact07.Notifications & Reminder, Contact
07.Notifications & Reminder, Contact
 
12.Maps and Location
12.Maps and Location12.Maps and Location
12.Maps and Location
 
11.Open Data Protocol(ODATA)
11.Open Data Protocol(ODATA) 11.Open Data Protocol(ODATA)
11.Open Data Protocol(ODATA)
 
10.Local Database & LINQ
10.Local Database & LINQ10.Local Database & LINQ
10.Local Database & LINQ
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
 
13.Windows Phone Store
13.Windows Phone Store13.Windows Phone Store
13.Windows Phone Store
 
06.Programming Media on Windows Phone
06.Programming Media on Windows Phone06.Programming Media on Windows Phone
06.Programming Media on Windows Phone
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation
 
04.Navigation on Windows Phone
04.Navigation on Windows Phone04.Navigation on Windows Phone
04.Navigation on Windows Phone
 
02.Designing Windows Phone Application
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone Application
 

03.Controls in Windows Phone

  • 1. Building Windows Phone Applications Nguyen Tuan | Microsoft Certified Trainer
  • 2. Agenda • Page navigation • Application Bar • Page Orientation • 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 ApplicationBar paints 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!
  • 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 8/16/2014 24
  • 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 8/16/2014 26 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); } } 8/16/2014 29
  • 33. Multiple Resolutions – Scaling & Touch 720p 720x1280 WVGA 480x800
  • 34. • 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? 8/16/2014 34 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
  • 35. Scaled Resolutions WVGA WXGA 720p 800 800 853 480 480 480
  • 36. • 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 8/16/2014 36 <Grid> <Grid.RowDefinitions> <RowDefinition Height="240"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> ... </Grid>
  • 37. Adaptive Layout Using Grid 8/16/2014 37 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
  • 38. • 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 8/16/2014 38
  • 39. • 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 8/16/2014 39
  • 40. • 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 8/16/2014 40 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 Language Support http://msdn.microsoft.com/en- us/library/windowsphone/develop/ff637520(v=vs.105).aspx
  • 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 8/16/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 8/16/2014 44
  • 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 8/16/2014 45
  • 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 8/16/2014 46
  • 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 8/16/2014 47
  • 49. The Windows Phone Toolkit
  • 50. WPToolkit • 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 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 8/16/2014 59
  • 60. Page Transitions and TiltEffect
  • 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