27
Charles Petzold www.charlespetzold.com Silverlight for Windows Phone

Charles Petzold Silverlight for Windows Phone

Embed Size (px)

Citation preview

Page 1: Charles Petzold  Silverlight for Windows Phone

Charles Petzoldwww.charlespetzold.com

Silverlight for Windows Phone

Page 2: Charles Petzold  Silverlight for Windows Phone

Agenda

• Windows Phone 7• Silverlight for Windows Phone• Your first phone application• Deploying to a device• Page orientation• Screen layout• Device information

Page 3: Charles Petzold  Silverlight for Windows Phone

• Meet or exceed a common hardware specification– Minimum 1 GHz ARM v7 CPU and DirectX9 GPU– Minimum 256 MB RAM and 8 GB flash storage– 480 x 800 screen (480 x 320 coming later)– Capacitive 4-point multi-touch screen– Minimum 5-megapixel camera– Location (Assisted-GPS), accelerometer,

compass, light sensor, and proximity sensor– Connectivity support via cellular networks and

WiFi • Available from Samsung, HTC, and other

OEMs

Windows Phones

Page 4: Charles Petzold  Silverlight for Windows Phone

• Operating system for Windows phones– Clean break from the past (Windows Mobile)– Released in U.S. on November 8, 2010

• "Metro" user interface– Crisp and sexy (icon grids are boring)– Start screen populated with tiles– Hubs that aggregate content (Pictures, Games,

etc.)• Built-in browser based on IE7 and IE8• Apps written in Silverlight or XNA

Windows Phone 7

Page 5: Charles Petzold  Silverlight for Windows Phone

• UI Design and Interaction Guide for WP7– http://go.microsoft.com/fwlink/?LinkID=183218

• WP7 Application Certification Requirements– http://go.microsoft.com/?linkid=9730558

Documents You Must Have

Page 6: Charles Petzold  Silverlight for Windows Phone

• Primary development platform for WP7 phones

• Based on Silverlight 3, but with some features of 4

• Adds many phone-specific features– Page orientation (portrait or landscape)– Richer touch APIs (Manipulation events)– Sensor and location APIs– Device APIs (e.g., camera)– Launchers and choosers and more

• Based on .NET Compact Framework 3.7

Silverlight for Windows Phone

Page 7: Charles Petzold  Silverlight for Windows Phone

• Windows Phone Developer Tools– Visual Studio 2010 Express for Windows Phone– Expression Blend for Windows Phone– Windows Phone Emulator– XNA Game Studio– http://www.microsoft.com/downloads/en/

details.aspx?FamilyID=04704acf-a63a-4f97-952c-8b51b34b00ce

• Silverlight for Windows Phone Toolkit– http://silverlight.codeplex.com/releases/view/

55034

Phone Developer Tools

Page 8: Charles Petzold  Silverlight for Windows Phone

• Runs phone apps in a VM• Supports multi-touch on PCs with multi-

touch screens and OSes that support multi-touch

• For best performance, enable hardware-assisted virtualization in your BIOS– http://www.microsoft.com/windows/virtual-pc/support/configure-bios.aspx

• For GPU emulation, run dxdiag.exe and make sure DDI version >= 10 and WDDM version >= 1.1– http://www.andybeaulieu.com/Default.aspx?

EntryID=196&tabid=67

Windows Phone Emulator

Page 9: Charles Petzold  Silverlight for Windows Phone

demoYour First Windows Phone Application

Page 10: Charles Petzold  Silverlight for Windows Phone

• Visual Studio supports deploying to the emulator or to a device (phone)

• To deploy to a device, you must:– Register and obtain a developer account

• http://create.msdn.com/en-us/home/membership

– Unlock the device with the Developer Registration Tool• http://msdn.microsoft.com/en-us/library/

ff769508(v=vs.92).aspx

– Download and install the Zune client• http://www.zune.net/en-US/products/software

• Debugger works with code running on a device!

Deploying to a Device

Page 11: Charles Petzold  Silverlight for Windows Phone

• Start the Zune client before deploying to device

• Media APIs not available while client is running

Zune Client

Page 12: Charles Petzold  Silverlight for Windows Phone

• First shipped in October 2010 tools update• Enables apps running on phones connected

to PCs to access media APIs

WPConnect

Page 13: Charles Petzold  Silverlight for Windows Phone

demoTesting on a Device

Page 14: Charles Petzold  Silverlight for Windows Phone

• Display can rotate when orientation changes

• PhoneApplicationPage.SupportedOrientations controls behavior when orientation changes– Portrait – Display does not rotate– Landscape – Display does not rotate– PortraitOrLandscape – Display rotates

automatically• PhoneApplicationPage.OrientationChanged

events fire when orientation changes– If SupportedOrientations =

"PortraitOrLandscape"

Page Orientation

Page 15: Charles Petzold  Silverlight for Windows Phone

Preventing the Page from Rotating// In MainPage.xamlSupportedOrientations="Portrait"

Page 16: Charles Petzold  Silverlight for Windows Phone

Rotating the Page

// In MainPage.xamlSupportedOrientations="PortraitOrLandscape"

Page 17: Charles Petzold  Silverlight for Windows Phone

Customizing the Rotated Page

// In the page constructorthis.OrientationChanged += new EventHandler<OrientationChangedEventArgs>(OnOrientationChanged);

private void OnOrientationChanged(object sender, OrientationChangedEventArgs e){ if ((e.Orientation & PageOrientation.Landscape) != 0) { // TODO: Adjust the page for landscape mode } else // Portrait { // TODO: Adjust the page for portrait mode }}

Page 18: Charles Petzold  Silverlight for Windows Phone

demoPage Orientation

Page 19: Charles Petzold  Silverlight for Windows Phone

Screen Layout

• Screen layout includes optional system tray and application bar

System tray32 pixels high in portrait mode72 pixels high in landscape mode

Application bar72 pixels high in portrait mode72 pixels high in landscape mode

Page 20: Charles Petzold  Silverlight for Windows Phone

Hiding the System Tray

// In MainPage.xaml<phone:PhoneApplicationPage x:Class="PhoneDemo.MainPage" ... FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="False">

Hide the system tray

Page 21: Charles Petzold  Silverlight for Windows Phone

Getting the Absolute Screen Sizedouble width = Application.Current.Host.Content.ActualWidth;double height = Application.Current.Host.Content.ActualHeight;

Page 22: Charles Petzold  Silverlight for Windows Phone

Getting the Usable Screen Sizedouble width = this.ActualWidth;double height = this.ActualHeight;

Page 23: Charles Petzold  Silverlight for Windows Phone

• DeviceExtendedProperties class provides information about host device

• Retrieve dictionary-type values with GetValue

Getting Device Information

Page 24: Charles Petzold  Silverlight for Windows Phone

DeviceExtendedProperties

Value Description Type

DeviceManufacturer Device manufacturer (e.g. SAMSUNG) string

DeviceName Device name (e.g., SGH-i917) string

DeviceUniqueId Device ID (e.g., 29-49-7B-05-D3-FA…) byte[]

DeviceFirmwareVersion

Firmware version (e.g., 2013.10.10.1) string

DeviceHardwareVersion

Hardware version (e.g., 3.1.0.7) string

DeviceTotalMemory Total memory (bytes) long

ApplicationCurrent-MemoryUsage

Memory currently allocated (bytes) long

ApplicationPeak-MemoryUsage

Peak memory allocated (bytes) long

Page 25: Charles Petzold  Silverlight for Windows Phone

Getting Model Information

string manufacturer = DeviceExtendedProperties.GetValue ("DeviceManufacturer").ToString();string name = DeviceExtendedProperties.GetValue ("DeviceName").ToString();string id = BitConverter.ToString((byte[]) DeviceExtendedProperties.GetValue("DeviceUniqueId"));

Page 26: Charles Petzold  Silverlight for Windows Phone

Getting Memory Information

string total = ((long)DeviceExtendedProperties.GetValue ("DeviceTotalMemory")).ToString("N0") + " bytes";string current = ((long)DeviceExtendedProperties.GetValue ("ApplicationCurrentMemoryUsage")).ToString("N0") + " bytes";string peak = ((long)DeviceExtendedProperties.GetValue ("ApplicationPeakMemoryUsage")).ToString("N0") + " bytes";

Page 27: Charles Petzold  Silverlight for Windows Phone

Charles Petzoldwww.charlespetzold.com

Questions?