360 likes | 568 Views
Sharing Skills and Code with Silverlight & WPF. Jeff Wilcox Software Development Engineer Microsoft Corporation. Sharing Skills and Code . Client Platform Vision What’s shared between Silverlight & WPF? Today’s controls and features Silverlight controls Silverlight Toolkit WPF Toolkit
E N D
Sharing Skills and Code with Silverlight & WPF Jeff Wilcox Software Development Engineer Microsoft Corporation
Sharing Skills and Code • Client Platform Vision • What’s shared between Silverlight & WPF? • Today’s controls and features • Silverlight controls • Silverlight Toolkit • WPF Toolkit • Building controls for Silverlight & WPF • Bringing it all together
Why? • Become a .NET expert once • Choice of .NET languages • Great Microsoft tools • Shared libraries and patterns • Develop a versatile skill set • Flexibility • Apply skills to RIA & LOB • Efficient • Not about building apps that “work just” everywhere
Client Platform Vision • Great platforms • Maximize reach with Silverlight • Add value with WPF • Shared skills, techniques, vocabulary • Create once, use everywhere • XAML • .NET code • Tests • World-class developer & designer tools
Current state of Microsoft Client Platforms • Silverlight 3 • Silverlight Toolkit • .NET 4 • We’re working to ensure compatibility
demo A simple shared app
What just happened? • Shared .NET platform • Shared development environment • Visual Studio • Blend • Shared components • Presentation platform • Rich charting and data grid controls • 100% the same source code
Shared .NET Framework • Great application platform • Powerful runtime • Great language support • C# • Visual Basic • Dynamic languages • Python • Ruby • Amazing communities
Business objects • Modern .NET business objects and logic “just work” • Collections • Generics • LINQ • Easy to add framework-specific value
Core Building Blocks • XAML • Rich compositing • Shapes • Visual tree • Managed framework • Dependency & attached properties • Events • Control model • Controls • Layout
Improving compatibility • Silverlight Toolkit • March 2009 release • Silverlight 2 and Silverlight 3 releases available • Silverlight 2 development continues • WPF Toolkit • Available today • .NET 4
Silverlight Toolkit • Fills today’s slight compatibility gap • Developing new controls with a rapid development cycle • Ships in the Silverlight SDK and on CodePlex
Silverlight Toolkit • WPF compatible controls • DockPanel • WrapPanel • TreeView • WPF compatible features • ImplicitStyleManager • LayoutTransformer • New controls offered for Silverlight & WPF • Charting • AutoCompleteBox
WPF Toolkit & .NET 4 • Calendar • DatePicker • DataGrid • VisualStateManager
Building controls • Step 1. Basics & C# strategy • Step 2. Source layout • Step 3. Dependency properties • Step 4. XAML • Step 5. Default styles • Step 6. VSM • Step 7. Wild hacks
Building controls • Step 1. Basics & C# strategy • Step 2. Source layout • Step 3. Dependency properties • Step 4. XAML • Step 5. Default styles • Step 6. VSM • Step 7. Wild hacks
C# Techniques • Partial classes • Extension methods and utility classes • Preprocessor directives #if SILVERLIGHT // Silverlight #else // WPF #endif
Source Layout • Peer folders for Silverlight & WPF • File links and source control Silverlight\ Control.csproj Control.cs Themes\Generic.xaml Wpf\ Control.csproj Control.cs Themes\Generic.xaml
Dependency Properties • Avoid WPF-specific metadata • Coercion • Read-only properties
Building controls • Step 1. Basics & C# strategy • Step 2. Source layout • Step 3. Dependency properties • Step 4. XAML • Step 5. Default styles • Step 6. VSM • Step 7. Wild hacks
XAML • Use WPF namespace • Watch out for the Silverlight 1.0 namespace xmlns=“http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" http://schemas.microsoft.com/client/2007
Building controls • Step 1. Basics & C# strategy • Step 2. Source layout • Step 3. Dependency properties • Step 4. XAML • Step 5. Default styles • Step 6. VSM • Step 7. Wild hacks
Default styles • Default styles and templates for controls are selected via DefaultStyleKey property • Defined differently • WPF: Static constructor • Silverlight: Instance constructor
Building controls • Step 1. Basics & C# strategy • Step 2. Source layout • Step 3. Dependency properties • Step 4. XAML • Step 5. Default styles • Step 6. VSM • Step 7. Wild hacks
Building controls • Step 1. Basics & C# strategy • Step 2. Source layout • Step 3. Dependency properties • Step 4. XAML • Step 5. Default styles • Step 6. VSM • Step 7. Wild hacks
Wild hacks • Declare routed events in a partial class • MyControl.Wpf.cs • Firing routed events source.OnSelectionChanged(new SelectionChangedEventArgs( #if SILVERLIGHT SelectionChangedEvent, #endif removed, added));
Wild hacks • Helper extension methods • Utility classes • Abstract out application model differences • Abstract Client Platform differences var x = new GlobalExceptionHandler(MyHandler); x.InterceptUnhandledExceptions = true;
demo Putting it all together
Please complete session feedback! • Deck and demo will be posted tonight • Silverlight Toolkithttp://silverlight.codeplex.com/ • Jeff Wilcox’s bloghttp://www.jeff.wilcox.name/
© 2009 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.