Cross Platform DevelopmentWindows 8 Windows Phone 8 Daniel Meixner
#dmxDevSession
Agenda
• Programmiermodelle
• Gemeinsamkeiten & Unterschiede
• Cross Plattform Strategien
Programmiermodell Windows 8
Programmiermodell Windows Phone 8
.NET API for
Windows
Phone
Windows
Phone
Runtime
Win32 &
COM
Managed Native
WP7.1 XAML & C#/VB
WP8.0 XAML & C#/VB
WP8.0 Games DirectX/Direct 3D & C++
WP7.1 XNA & C#/VB
WP8.0 XAML & C#/VB with Direct3D Graphics
+ C++
+ C++
Shared core
Full WinRT11,000 members
Windows Phone Runtime2,800 shared members
600 new members
Gemeinsamkeiten & Unterschiede
3/15/2013
Screen Size
Windows Phone
• 800x480, 1280x720, 1280x768Portrait, Landscape
Windows
• 1024x768 Portrait, Landscape, Snapped
Controls
Windows Phone
• Panorama, Pivot, ListPickerLongListSelector
Windows
• GridView, ListView, Semantic Zoom, FlipView
Lifecycle
Windows Phone
• Launched from start/apps list.Tombstones apps
Windows
• Resumes existing appsNo tombstoning
Cross Plattform Strategien (XAML/C#)
Reuse: Portable Class Library
Reusing pre-built components or libraries
3/15/2013Microsoft
confidential
9
• Portable Class Library
• Managed Code
• Reusable library
• One codebase with no conditional compilation
Shared Code: File-Level (Add as Link)
• App logic common to both apps, but not portable
• Code containing Windows Runtime API calls
• User controls with no platform dependencies
Shared Code: Classpart-Level (Partial Classes)
public partial class MyClass{
public void CommonMethodA(){
// code that is common}
public int CommonMethodB(){
int result = 0;// code that is commonreturn result;
}
}
public partial class MyClass{
public void PlatformSpecificMethod(){
// specific code for platform Á}
}}
public partial class MyClass{
public void PlatformSpecificMethod(){
// specific code for platform B}
}
Shared Code: Classpart-Level (Partial Classes)
• Very useful if amount of common code is large relative to the amount of platform-specific code
• I cannot specify what each platform-specific partial class should implement
Shared Code: Line Level (Conditional Compilation)
• can’t be shared in a Portable Class Library
• simple way to share code
• Complexity!
public class MyClass{
public void CommonMethodA(){
// code that is common to Windows Phone 8 and Windows 8}
public int CommonMethodB(){
int result = 0;// code that is common to Windows Phone 8 and Windows 8return result;
}
public void PlatformSpecificMethod(){
#if NETFX_CORE// code for Windows 8#else// code for Windows Phone 8#endif
}}
Shared UI: XAML Controls
• Limited to basic user controls
• Always build your user experience to suit the target platform!
<UserControl x:Class="MyApp.Shared.Controls.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" Background="Black">
<StackPanel >
<TextBox x:Name="InputText"/>
<Button x:Name="SayHelloButton" Content="Say Hello!"/>
</StackPanel>
</Grid>
</UserControl>
public class MyWin8Class : MyBaseClass{
public override void PlatformSpecificMethod(){// Implement this method specific to Win 8}
} }
Patterns: Abstract Base Class
public abstract class MyBaseClass{
public void CommonMethodA(){
// code that is common}
public int CommonMethodB(){
int result = 0;
// code that is commonreturn result;
}
public abstract void PlatformSpecificMethod();}
Add as Link
Portable Class Library
public class MyWP8Class : MyBaseClass{
public override void PlatformSpecificMethod(){// Implement this method specific to WP8}
}
public class MyClass{
private IPlatformSpecificCode _platformImpl;
public MyClass(IPlatformSpecificCode platformImpl){
_platformImpl = platformImpl;}
public void CommonMethodA(){ ... }
public int CommonMethodB(){ ... }
public void PlatformSpecificMethod(){
_platformImpl.PlatformSpecificMethodImpl();}
}
public interface IPlatformSpecificCode{
void PlatformSpecificMethodImpl();}
// Windows 8 app projectpublic class MyWin8Implementation : IPlatformSpecificCode
{public void PlatformSpecificMethod(){
// Implemented for Windows 8}
}
Patterns: Interfaces
// Windows Phone app projectpublic class MyWinPhone 8Implementation : IPlatformSpecificCode
{public void PlatformSpecificMethod(){
// Implemented for Windows Phone 8}
}
Demo
Summary
• Shared design language
• Shared core
• Several approaches to share parts
3/15/2013Microsoft
confidential
1
8
Daniel MeixnerTechnical Evangelist
#dmxDevSession
Ping me!
© 2013 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.
The information herein is for informational purposes only and 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. MICROSOFT MAKES
NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Vielen Dank.