SlideShare una empresa de 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

Más contenido relacionado

Destacado (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
 

Similar 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
 

Similar 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

Último (20)

10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Buy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdfBuy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdf
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 

.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 del 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.