SlideShare uma empresa Scribd logo
1 de 23
a tale from the “real” world .NET Code ReuseWPF | Silverlight | Windows Phone
tonight's topic WPF Silverlight VS
agenda Who is this guy? What is he doing? Why is he doing it? How is he doing it?
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)
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
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?
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.
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
Let’s try it out  I can haz code?
re-cap 1/4 Use compiler conditionals for platform specific code: #if WINDOWS_PHONE    //Windows phone 7#elif SILVERLIGHT    //Silverlight #else    //.NET #endif
re-cap 2/4 Theme style declared differently: Silverlight / Phone: public HoverControl() { #if SILVERLIGHT this.DefaultStyleKey = typeof(HoverControl); #endif} WPF: static HoverControl() { #if !SILVERLIGHT DefaultStyleKeyProperty.OverrideMetadata( typeof(HoverControl), 	new FrameworkPropertyMetadata( typeof(HoverControl)));  #endif }
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.
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 
xaml reader #if SILVERLIGHT element = XamlReader.Load(xaml); #else 	using (MemoryStream xamlStream =  	new MemoryStream(UTF8Encoding.Default.GetBytes( xaml))) element = XamlReader.Load(xamlStream); #endif
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;  
stop-modify-start animations #if SILVERLIGHT  myStoryboard.Begin();  myStoryboard.Stop();  #else  myStoryboard.Begin(element, true); myStoryboard.Stop(element); #endif
in what order does what event fire? <UserControl Loaded="UserControl_Loaded"> <my:Control Loaded="MyControl_Loaded" /> </UserControl>  Constructor Loaded OnApplyTemplate
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*
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
questions?
thank you ! contact info: name: Morten Nielsen email: mnielsen@esri.com twitter: @sharpgis blog: www.sharpgis.net Passionate about XAML? We’re hiring! www.esri.com/careers

Mais conteúdo relacionado

Destaque (7)

Sơn bả chống thấm tường quận Hoàn Kiếm Hà Nội, quận 11 HCM
Sơn bả chống thấm tường quận Hoàn Kiếm Hà Nội, quận 11 HCMSơn bả chống thấm tường quận Hoàn Kiếm Hà Nội, quận 11 HCM
Sơn bả chống thấm tường quận Hoàn Kiếm Hà Nội, quận 11 HCM
 
Lobby Moedertaalonderwijs Agatha Van Ginkel 2010
Lobby Moedertaalonderwijs Agatha Van Ginkel 2010Lobby Moedertaalonderwijs Agatha Van Ginkel 2010
Lobby Moedertaalonderwijs Agatha Van Ginkel 2010
 
IoT
IoTIoT
IoT
 
Kesesuaian jenis percobaan
Kesesuaian jenis percobaanKesesuaian jenis percobaan
Kesesuaian jenis percobaan
 
Waiting on Machines
Waiting on MachinesWaiting on Machines
Waiting on Machines
 
Much ado about...documents
Much ado about...documentsMuch ado about...documents
Much ado about...documents
 
Propeller UI/UX Process
Propeller UI/UX ProcessPropeller UI/UX Process
Propeller UI/UX Process
 

Semelhante a .NET code reuse

Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGap
Mihai Corlan
 
"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap
Christian Rokitta
 
Windowsphone7
Windowsphone7Windowsphone7
Windowsphone7
yuvaraj72
 
Build Cross-Platform Mobile Application with PhoneGap
Build Cross-Platform Mobile Application with PhoneGapBuild Cross-Platform Mobile Application with PhoneGap
Build Cross-Platform Mobile Application with PhoneGap
Allan Huang
 

Semelhante a .NET code reuse (20)

Complete WPF Overview Tutorial with Example - iFour Technolab
Complete WPF Overview Tutorial with Example - iFour TechnolabComplete WPF Overview Tutorial with Example - iFour Technolab
Complete WPF Overview Tutorial with Example - iFour Technolab
 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGap
 
Windows Phone
Windows Phone Windows Phone
Windows Phone
 
Phone gap
Phone gapPhone gap
Phone gap
 
Portfolio
PortfolioPortfolio
Portfolio
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Silverlight vs WPF
Silverlight vs WPFSilverlight vs WPF
Silverlight vs WPF
 
PhoneGap/Cordova
PhoneGap/CordovaPhoneGap/Cordova
PhoneGap/Cordova
 
"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap
 
Mobile Java with GWT: Still "Write Once, Run Everywhere"
Mobile Java with GWT: Still "Write Once, Run Everywhere"Mobile Java with GWT: Still "Write Once, Run Everywhere"
Mobile Java with GWT: Still "Write Once, Run Everywhere"
 
Introduction to Microsoft Silverlight
Introduction to Microsoft SilverlightIntroduction to Microsoft Silverlight
Introduction to Microsoft Silverlight
 
Windowsphone7
Windowsphone7Windowsphone7
Windowsphone7
 
TechDays Switzerland 2009
TechDays Switzerland 2009TechDays Switzerland 2009
TechDays Switzerland 2009
 
A First Look at Windows Presentation Foundation Everywhere (WPF/E): a Cross …
A First Look at Windows Presentation Foundation Everywhere (WPF/E): a Cross …A First Look at Windows Presentation Foundation Everywhere (WPF/E): a Cross …
A First Look at Windows Presentation Foundation Everywhere (WPF/E): a Cross …
 
Build Cross-Platform Mobile Application with PhoneGap
Build Cross-Platform Mobile Application with PhoneGapBuild Cross-Platform Mobile Application with PhoneGap
Build Cross-Platform Mobile Application with PhoneGap
 
phonegap_101
phonegap_101phonegap_101
phonegap_101
 
From Windows Presentation Foundation To Silverlight
From Windows Presentation Foundation To SilverlightFrom Windows Presentation Foundation To Silverlight
From Windows Presentation Foundation To Silverlight
 
Architecting applications for Windows 8 and Windows Phone 8 by Karl Ots / @f...
Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @f...Architecting applications for Windows 8 and Windows Phone 8  by Karl Ots / @f...
Architecting applications for Windows 8 and Windows Phone 8 by Karl Ots / @f...
 
Ignite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseIgnite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and Firebase
 
Core data intermediate Workshop at NSSpain 2013
Core data intermediate Workshop at NSSpain 2013Core data intermediate Workshop at NSSpain 2013
Core data intermediate Workshop at NSSpain 2013
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

.NET code reuse

  • 1. a tale from the “real” world .NET Code ReuseWPF | Silverlight | Windows Phone
  • 2. tonight's topic WPF Silverlight VS
  • 3.
  • 4.
  • 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
  • 11. Let’s try it out I can haz code?
  • 12. re-cap 1/4 Use compiler conditionals for platform specific code: #if WINDOWS_PHONE //Windows phone 7#elif SILVERLIGHT //Silverlight #else //.NET #endif
  • 13. re-cap 2/4 Theme style declared differently: Silverlight / Phone: public HoverControl() { #if SILVERLIGHT this.DefaultStyleKey = typeof(HoverControl); #endif} WPF: static HoverControl() { #if !SILVERLIGHT DefaultStyleKeyProperty.OverrideMetadata( typeof(HoverControl), new FrameworkPropertyMetadata( typeof(HoverControl))); #endif }
  • 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;  
  • 18. stop-modify-start animations #if SILVERLIGHT myStoryboard.Begin(); myStoryboard.Stop(); #else myStoryboard.Begin(element, true); myStoryboard.Stop(element); #endif
  • 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
  • 23. thank you ! contact info: name: Morten Nielsen email: mnielsen@esri.com twitter: @sharpgis blog: www.sharpgis.net Passionate about XAML? We’re hiring! www.esri.com/careers

Notas do Editor

  1. Show ThreePlatforms demo. Start with Silverlight. Then include MapPage.xaml/.cs into WP7 and WPF.
  2. Note that SILVERLIGHT conditional also includes Windows Phone.
  3. Note that SILVERLIGHT conditional also includes Windows Phone.
  4. Note that SILVERLIGHT conditional also includes Windows Phone.
  5. Can become a problem with WinPhone, which doesn’t support xmlns namespace mapping that uses a catch-all schema
  6. 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.
  7. SilverlightUserControl ConstructorMyControl ConstructorMyControl LoadedUserControl LoadedMyControl.OnApplyTemplateWPFUserControl ConstructorMyControl ConstructorMyControl.OnApplyTemplateUserControl LoadedMyControl Loaded
  8. 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.