Silverlight 2 for Developers - TechEd New Zealand 2008

5,210 views
4,168 views

Published on

The slides from the WEB308 Silverlight 2 for Developers talk at TechEd New Zealand 2008

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,210
On SlideShare
0
From Embeds
0
Number of Embeds
594
Actions
Shares
0
Downloads
254
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide
  • 06/04/09 12:30 © 2007 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.
  • Silverlight 2 for Developers - TechEd New Zealand 2008

    1.  
    2. Silverlight 2 for Developers Jonas Follesø Senior Consultant Capgemini Session Code: WEB304
    3.  
    4. Agenda <ul><li>Blend 2.5 </li></ul><ul><li>CRUD </li></ul><ul><li>Designers </li></ul><ul><li>Patterns </li></ul><ul><li>Testing </li></ul><ul><li>Q&A </li></ul>
    5. Dive Log App
    6. Outside data Public Internet mashup APIs Existing Intranet services New services you build RSS/Atom Feeds Images Sounds Videos
    7. A bit of history: Silverlight 1 JavaScript HTML ? AJAX (XmlHttpRequest) 1.0 <XAML/> Public Internet mashup APIs Existing Intranet services New services you build RSS/Atom Feeds Images Sounds Videos
    8. Today: Silverlight 2 2 Managed Code (C#/VB) HTML Public Int e rnet mashup APIs Existing Intr a net services New services you build RSS/Atom Feeds Images Sounds Videos
    9. Services that describe themselves Computer-Readable Metadata (e.g. WSDL) Automatic Proxy Generation WCF SOAP services in the enterprise Services for your Silverlight project ADO.NET Data Services SOAP services on the Internet
    10. Securing Silverlight Services Silverlight will use auth. info in the browser HTML E.g.: ASP.NET Login User: Password : Credentials Auth info (e.g. cookie) Service calls + Auth info Silverlight code does not normally deal with credentials… DiveLog.com …/Login.aspx ../MyApp.aspx ../MyService.svc
    11. HTTP Requests in Silverlight HttpWebRequest High-level components and User Code Browser Plugin APIs Web Browser - Cookies - Authenticated sessions - Caching - Proxy server to use Windows/Mac Networking Layer Restrictions Restrictions
    12. Blend – The dark is not that scary…
    13. Dive Log UI and Data
    14. Everything in code behind …is probably not a good idea
    15. A team of sad coders and designers
    16.  
    17. Different people reading about MVC in different places take different ideas from it and describe these as “MVC”. Martin Fowler, GUI Architectures Essay
    18. Separated Presentation Patterns
    19. Data & Domain Logic (Model) UI (View) Interaction (Controller/Presenter)
    20. Represent the state and behavior of the presentation independently of the GUI controls used in the interface. Martin Fowler, Presentation Model Essay
    21. Makes your app easier to design …makes the designers like you
    22. Everything in code-behind Data Model View XAML Code-Behind Event Handlers
    23. Presentation Model Change notification Data-binding and commands Data Model View XAML Code-Behind Presentation Model State + Operations
    24. Dive Log Presentation Model Change notification Data-binding and commands Dive Log Service Dive Log XAML Code-Behind Dive Log View Model State + Operations
    25. Data Binding <ul><li>Implement INotifyPropertyChanged and use ObservableCollection<T> for collections </li></ul>View < ListBox ItemsSource =&quot;{Binding Path=Dives}&quot; SelectedItem =&quot;{Binding Path=SelectedDive, Mode=TwoWay}&quot; /> Presentation Model State + Operations
    26. Data Binding <ul><li>Implement INotifyPropertyChanged and use ObservableCollection<T> for collections </li></ul>View XAML Code-Behind Presentation Model public class PageViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public ObservableCollection < Dive > Dives { ... } public Dive SelectedDive { ... } }
    27. IValueConverter <ul><li>Converts data bound values </li></ul><ul><ul><li>E.g. Bind temperature to color </li></ul></ul>public object Convert( object , value, Type targetType, object parameter, CultureInfo culture) { int temp = System. Convert .ToInt32(value); Color color = Colors .Black; if (temp < 5) color = Colors .Blue; else if (temp < 20) color = Colors .Yellow; else color = Colors .Red; return new SolidColorBrush (color); } View < UserControl.Resources > < demo:ColorConverter x:Key =&quot;colorConverter&quot; /> </ UserControl.Resources > < TextBox Text =&quot;{Binding Temperature, Mode=TwoWay}&quot; Background =&quot;{Binding Temperature, Converter={StaticResource colorConverter}}&quot;/>
    28. Building a Presentation Model
    29. User Interaction <ul><li>But what about Word? </li></ul>View private void btnSave_Clicked( object sender, ExecutedEventArgs e) { (( PageViewModel )DataContext).Save(); }
    30. Objects are used to represent actions. A command object encapsulates an action and its parameters. This allows a decoupling of the invoker of the command and the handlers of the command.
    31. Commands in Silverlight View < Button Content =&quot;Save Dives&quot; input:CommandService.Command =&quot;SaveDives&quot; /> Presentation Model public PageViewModel() { Commands .SaveDives.Executed += new EventHandler < ExecutedEventArgs >(SaveDives); } private void SaveDives( object sender, ExecutedEventArgs e) { // code to save dives.. }
    32. The strategy pattern is a software design pattern, whereby algorithms can be selected at runtime . Presentation Model public PageViewModel() { if ( HtmlPage .IsEnabled) { client = new DiveLogServiceClient (); } else { client = new ServiceStub (); } }
    33.  
    34.  
    35. Dealing with dependencies <ul><li>The Presentation Model is coupled with both the stub service and the real service. </li></ul><ul><li>Makes code less flexible for change </li></ul><ul><li>Makes code harder to test </li></ul><ul><li>Object should not be responsible for creating their own dependencies – Inversion of Control </li></ul>
    36. Dependency Injection (DI) <ul><li>One form of Inversion of Control (IoC) </li></ul><ul><li>Create dependencies outside the object and, inject them into it </li></ul><ul><li>But who creates the dependency? </li></ul>Presentation Model public PageViewModel( IDiveLogServiceClient proxy) { this. proxy = proxy }
    37. Dependency Injection by hand <ul><li>Should the page be responsible for creating dependencies? </li></ul>View public Page() { InitializeComponent(); if ( HtmlPage .IsEnabled) this .DataContext = new PageViewModel ( new DiveLogServiceClient ()); else this .DataContext = new PageViewModel ( new ServiceStub ()); }
    38. IoC Containers Presentation Model [ Inject ] public PageViewModel( IDiveLogServiceClient proxy) { this. proxy = proxy } View public Page() { InitializeComponent(); IKernel iocContainer = new StandardKernel (); this .DataContext = iocContainer.Get< PageViewModel >(); }
    39. IoC Containers <ul><li>What about design time support in Blend? </li></ul><ul><li>Need to find a way to use IoC and set DataContext declaratively… </li></ul>View < UserControl.DataContext > < dive:PageViewModel /> </ UserControl.DataContext >
    40. Using DI on the ViewModel
    41. Testing is important!
    42. Testing Silverlight Code <ul><li>The standard solutions do not apply </li></ul><ul><ul><li>The Silverlight CLR is a subset </li></ul></ul><ul><ul><li>All networking is asynchronous </li></ul></ul><ul><li>But it’s still familiar… </li></ul><ul><ul><li>[TestClass], [TestMethod], [Asynchronous] </li></ul></ul>
    43. Asynchronous Tests <ul><li>How do we “wait” before doing assertions? </li></ul>
    44. Unit Testing in Silverlight
    45.  
    46. Resources <ul><li>www.microsoft.com/teched </li></ul><ul><ul><li>Tech·Talks Tech·Ed Bloggers </li></ul></ul><ul><ul><li>Live Simulcasts Virtual Labs </li></ul></ul><ul><li>http://microsoft.com/technet </li></ul><ul><ul><li>Evaluation licenses, pre-released products, and MORE! </li></ul></ul><ul><li>http://microsoft.com/msdn </li></ul><ul><ul><li>Developer’s Kit, Licenses, and MORE! </li></ul></ul>
    47. Related Content <ul><li>Code and lots of good resources on http://jonas.follesoe.no </li></ul><ul><li>WEB311 Designing Compelling Silverlight User Experiences with Expression Studio 2 </li></ul><ul><li>Wednesday, 3-9-2008 14:20 - 15:35, NZ Room 4, SkyCity </li></ul><ul><li>Hands-on Labs (session codes and titles) </li></ul>
    48. Track Resources <ul><li>WEB311 Designing Compelling Silverlight User Experiences with Expression Studio 2 </li></ul><ul><li>Wednesday, 3-9-2008 14:20 - 15:35, NZ Room 4, SkyCity </li></ul>
    49. Please complete an evaluation
    50. © 2008 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.
    51. Photo Copyright Notices <ul><li>All diving photos taken by Hege Røkenes and licensed under the creative commons license. http://flickr.com/photos/hegerokenes/ </li></ul><ul><li>Photos of Martin Fowler taken by Dave Thomas and licensed under the creative commons license. http://flickr.com/photos/pragdave/ </li></ul>

    ×