SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

En vedette (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
 

Similaire à .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
 

Similaire à .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
 

Dernier

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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

.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

Notes de l'éditeur

  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.