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
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
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
UI Design and Interaction Guide for WP7 – WP7 Application Certification Requirements – Documents You Must Have
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
Windows Phone Developer Tools –Visual Studio 2010 Express for Windows Phone –Expression Blend for Windows Phone –Windows Phone Emulator –XNA Game Studio – amilyID=04704acf-a63a-4f97-952c-8b51b34b00ce Silverlight for Windows Phone Toolkit – Phone Developer Tools
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 – For GPU emulation, run dxdiag.exe and make sure DDI version >= 10 and WDDM version >= 1.1 – Windows Phone Emulator
demo Your First Windows Phone Application
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 –Unlock the device with the Developer Registration Tool –Download and install the Zune client Debugger works with code running on a device! Deploying to a Device
Start the Zune client before deploying to device Media APIs not available while client is running Zune Client
First shipped in October 2010 tools update Enables apps running on phones connected to PCs to access media APIs WPConnect
demo Testing on a Device
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
Preventing the Page from Rotating // In MainPage.xaml SupportedOrientations="Portrait"
Rotating the Page // In MainPage.xaml SupportedOrientations="PortraitOrLandscape"
Customizing the Rotated Page // In the page constructor this.OrientationChanged += new EventHandler (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 }
demo Page Orientation
Screen Layout Screen layout includes optional system tray and application bar System tray 32 pixels high in portrait mode 72 pixels high in landscape mode Application bar 72 pixels high in portrait mode 72 pixels high in landscape mode
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
Getting the Absolute Screen Size double width = Application.Current.Host.Content.ActualWidth; double height = Application.Current.Host.Content.ActualHeight;
Getting the Usable Screen Size double width = this.ActualWidth; double height = this.ActualHeight;
DeviceExtendedProperties class provides information about host device Retrieve dictionary-type values with GetValue Getting Device Information
DeviceExtendedProperties ValueDescriptionType DeviceManufacturer Device manufacturer (e.g. SAMSUNG)string DeviceName Device name (e.g., SGH-i917)string DeviceUniqueId Device ID (e.g., B-05-D3-FA…)byte[] DeviceFirmwareVersion Firmware version (e.g., )string DeviceHardwareVersion Hardware version (e.g., )string DeviceTotalMemory Total memory (bytes)long ApplicationCurrent- MemoryUsage Memory currently allocated (bytes)long ApplicationPeak- MemoryUsage Peak memory allocated (bytes)long
Getting Model Information string manufacturer = DeviceExtendedProperties.GetValue ("DeviceManufacturer").ToString(); string name = DeviceExtendedProperties.GetValue ("DeviceName").ToString(); string id = BitConverter.ToString((byte[]) DeviceExtendedProperties.GetValue("DeviceUniqueId"));
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";
Charles Petzold Questions?