5. agenda Who is this guy? What is he doing? Why is he doing it? How is he doing it?
6. who is this guy? Morten Nielsen (@sharpgis) Esri – World leader in GIS software Lead Developer ArcGIS API for Silverlight, WPF & WinPhone 7 http://esriurl.com/sl Silverlight MVP Danish (sorry for the accent)
7. what is he doing? ArcGIS API for Silverlight, WPF, WP7 Client API for creating advanced GIS analysis on the web Free developer download: http://esriurl.com/slSamples: http://esriurl.com/slsdk
8. how did he get into this "mess"? It all started with WPF/E… a.k.a Silverlight v1.1alpha… a.k.a. Silverlight v2 I wonder if this can compile into WPF? I wonder if this can compile into WinPhone?
9. advantages Write once! Reuse (WPF), reuse (Silverlight), reuse (Phone), reuse (Xbox?), reuse (???) In other words: Triple your productivity Always syncronizedDataContracts Compile data contracts for both server and client – simple reuse.
10. the gotcha’s Write once; -but: Test, Test, Test… In other words: Triple you testing efforts Different screens – Different experiences Silverlight is a subset of WPF But Silverlight moves faster than WPF! Windows Phone is always a version behind Silverlight
14. re-cap 3/4 No VisualStateManager in WPF v3.5 Use WpfToolkithttp://wpf.codeplex.com WPF doesn’t like linked XAML files if they are not located in the project root.
15. xaml conditionals <Grid x:Name="LayoutRoot" Background="White"> <controls:HoverControl>#if SILVERLIGHT <TextBlock Text="Hello from Silverlight" />#else<TextBlock Text="Hello from .NET" />#endif</controls:HoverControl> </Grid> No compiler conditionals in XAML! You might have to duplicate XAML
16. xaml reader #if SILVERLIGHT element = XamlReader.Load(xaml); #else using (MemoryStream xamlStream = new MemoryStream(UTF8Encoding.Default.GetBytes( xaml))) element = XamlReader.Load(xamlStream); #endif
17. create bitmap BitmapImagebmi = new BitmapImage(); #if !SILVERLIGHTbmi.BeginInit(); #endif Image img = new Image(); bmi.UriSource= new Uri(strUrl, UriKind.Absolute); #if SILVERLIGHTimg.ImageFailed+= img_ImageFailed; #else bmi.DownloadFailed+= bmi_DownloadFailed; bmi.EndInit(); #endif img.Source= bmi;
19. in what order does what event fire? <UserControl Loaded="UserControl_Loaded"> <my:Control Loaded="MyControl_Loaded" /> </UserControl> Constructor Loaded OnApplyTemplate
20. binary compatibility Assembly-sharing Compile for Silverlight 4 Reuse in WPF However: ONLY following assemblies supported: mscorlib.dll System.dll. System.Core.dll System.ComponentModel.Composition.dll Microsoft.VisualBasic.dll No UI logic! Windows Phone: Compile for Silverlight 3, and re-use as is*
21. the bottom line: Yes you CAN reuse a LOT of code, and you should! …but: Develop UX for the screen Web: Links, navigation, sandboxed Desktop: Menus, multiple windows, file access Phone: Touch centric, small screen
Show ThreePlatforms demo. Start with Silverlight. Then include MapPage.xaml/.cs into WP7 and WPF.
Note that SILVERLIGHT conditional also includes Windows Phone.
Note that SILVERLIGHT conditional also includes Windows Phone.
Note that SILVERLIGHT conditional also includes Windows Phone.
Can become a problem with WinPhone, which doesn’t support xmlns namespace mapping that uses a catch-all schema
Silverlight can change animations on the fly.WPF: Animations are by default frozen.Begin: True parameter allows for changing animation later (not frozen).Stop: element parameter required when Begin was called with element.
Assemblies built in Silverlight 2 and 3 are not binary compatible with the .NET Framework, so if you want to share code you need generally need to dual-compile. With Silverlight 4 and .NET 4, you will be able to use some Silverlight-based assemblies from within .NET 4.In order to load a Silverlight assembly in .NET, the assembly may only reference the following assemblies: •Mscorlib•System•System.Core•System.ComponentModel.Composition•Microsoft.VisualBasicOther assemblies such as System.Xml and System.Net are not currently supported, nor are any of the UI libraries. This means sharing passive data objects is possible but active records that can call services or handle their own XML serialization are out of the question.One should also note that loading .NET assemblies in Silverlight is explicitly not supported. Since the non-UI parts of Silverlight are a directly subset of .NET, they felt it was less error prone to do it this way than to try to deal with countless missing classes and methods.If you would like to learn more about assembly portability or want to report an incompatibility between Silverlight and .NET, you can do so on the CLR Team blog.