1 / 64

Tips in Silverlight

10. Tips in Silverlight. Gill Cleeren Microsoft Regional Director MVP ASP.NET Ordina .net software architect. About Gill. .net architect Ordina ( ordina.be ) Microsoft Regional Director ( theregion.com ) MVP ASP.net Writing: .net magazine Blogs MSDN Speaking: TechDays

diandra
Download Presentation

Tips in Silverlight

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 10 Tips in Silverlight Gill Cleeren Microsoft Regional Director MVP ASP.NETOrdina .net software architect

  2. About Gill... • .net architect Ordina (ordina.be) • Microsoft Regional Director (theregion.com) • MVP ASP.net • Writing: • .net magazine • Blogs • MSDN • Speaking: • TechDays • Usergroups(Visug, Biwug, Besug) • Ineta speaker • Blog: snowball.be • Email: gill.cleeren@snowball.be • Twitter: gillcleeren / MSN: gillcleeren@hotmail.com

  3. I present you... the tips • Creating a custom install experience • ASP.NET Membership Integration • Double clickety-click • Debugging services • Duplex services • Silverlight and SEO • Virtual Earth in Silverlight • Drag’n’drop and hit testing • Model-View-ViewModel • Async unit tests

  4. 1 Creating a custom install experience with Silverlight

  5. Developers, developers, developers... • Developers create great Silverlight apps • They forget one thing: the install experience! • Maybe they’re happy with the “Silverlight Badge” • Default if the app was created with Visual Studio 2008 and Silverlight tools

  6. Why do should we care? • Problem: • Users don’t understand this medallion • Think it’s a banner • They wonder if it’s worth installing (they don’t see your fancy app just yet...) • They might be afraid to install something, we should encourage them, perhaps tease them •  In short, the user is confused! Don’t you want everybody to enjoy your application?

  7. Some research was done... And the following was the result... • Let the content jump out! • Convince users that Silverlight is thrustworthy • Show users how to do it • They’re not all developers • Make the experience interactive  Tease them with what they can expect inside!

  8. What would you choose?

  9. Convinced? OK! Let’s build a better experience... • To start with, a PC can be in several states

  10. It all started with a simple <object> Steps needed to get a great install UX • Configure Silverlight’s object tag • Render UI prompts • Capture callbacks from Silverlight.js

  11. What you need From bad to great...

  12. Creating a custom install experience with Silverlight Demo

  13. 2 ASP.NET MembershipIntegration

  14. ASP.NET membership integration You need to authenticate users? You need to authorize users? You want to create profiles? One answer: use ASP.NET membership ... Yes, in Silverlight!

  15. A small intro in Membership & Co • Manages users and credentials • Declarative access via W.S. Admin Tool • Programmatic access via Membership API • Simplifies forms authentication • Provides logic for validating user names and passwords, creating users, and more • Manages data store for credentials, e-mail addresses, and other membership data • Provider-based for flexible data storage

  16. The Membership API in-a-slide Membership architecture Controls Login LoginStatus LoginView Other Controls Membership API Membership MembershipUser Membership Providers SqlMembershipProvider ActiveDirectory- MembershipProvider Other Membership Providers Membership Data SQL Server Active Directory Other Data Stores

  17. Membership class • Provides static methods for performing key membership tasks • Creating and deleting users • Retrieving information about users • Generating random passwords • Validating logins • Includes read-only static properties for acquiring data about provider settings

  18. Roles • Role-based security in a box • Declarative access via W.S. Admin Tool • Programmatic access via Roles API • Simplifies adding role-based security to sites that employ forms authentication • Maps users to roles on each request • Provides data store for role information • Provider-based for flexible data storage

  19. Profiles • Store per-user data persistently • Strongly typed (unlike session state) • On-demand lookup (unlike session state) • Long-lived (unlike session state) • Supports authenticated and anonymous users • Accessed through dynamically compiled ProfileBase derivatives • Provider-based for flexible data storage

  20. ... OK, great... I’m here to learn about Silverlight! How can I access server-side code?

  21. ASP.NET Application Services • Built-in Web services that provide access to features such as forms authentication, roles, and profile properties • Useful for many types of client applications • Internally, they use SOAP

  22. ASP.NET Application Services

  23. ASP.NET Application Services • 3 available services: • Authentication service • Roles service • Profile service • WCF services

  24. ASP.NET Membership Integration Demo

  25. 3 Doubleclickety-click

  26. Silverlight and double-click • A click: depression of a button on a computer mouse; “a click on the left button for example” • A double-click: well, the same, but very fast after one another • Silverlight does not have built-in support for double-clicking

  27. Solution 1: use ticks between clicks private void myTextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (DateTime.Now.Ticks - currentTicks < 2310000) { //yes, bingo, a double click! myResultTextBlock.Text = "A doubleclick, you did it"; } else { //try harder... myResultTextBlock.Text = "FAIL"; } currentTicks = DateTime.Now.Ticks; }

  28. Solution 2: Triggers (SL3 only) • Behaviors: reusable piece of interactivity that you can attach to any element • No more copy/paste • Changes element functionality • See Expression Gallery

  29. Behaviors and Co • Behaviors is actually composed out of • Behavior • Trigger: • causes an Action to happen • Starts the behavior • Action • Let’s create a double-click trigger

  30. Doubleclickety-click Demo

  31. 4 Debuggingservices

  32. Services debugging in SL2 • Services are not nice when debugging! • Error in Silverlight 2 is not returned to client • OK when you have access to the server • NOK when you don’t

  33. Debugging services from SL2 to SL3 • Attempt 1: just run the service • No error info on the wire • Nothing in Silverlight • Attempt 2: IncludeExceptionDetailsInFaults=true • Visible in Fiddler • Still nothing in Silverlight • Cause: sends back HTTP status 500 • Silverlight can’t work with that •  Convert to HTTP status 200 and use SL3

  34. Debuggingservices Demo

  35. 5 Duplexservices

  36. Duplex services • Useful for real-time interaction (e.g. chat),monitoring (e.g. stock ticker), etc. • “Duplex” feature introduced in Silverlight 2 • Based on “smart polling” • Hard to use in SL2 • Advanced WCF knowledge required • Significantly simplified in Silverlight 3 Beta1 • May improve even more after the Beta

  37. Client side • 1. “Add Service Reference” • 2. Open the Proxy (Config not supported) • May get easier in final SL3 release • 3. Call Methods and Handle Events EndpointAddress address = new EndpointAddress("http://example.com/Service1.svc"); CustomBinding binding = new CustomBinding( new PollingDuplexBindingElement(), new TextMessageEncodingBindingElement( MessageVersion.Soap12WSAddressing10, Encoding.UTF8), new HttpTransportBindingElement());

  38. Server side • 1. Define a Service with a Callback Contract • [ServiceContract(CallbackContract=…)] • [OperationContract(IsOneWay=true)] • 2. Implement the service • OperationContext.Current .GetCallbackChannel<ICallbackContract>() • 3. Host the service • No config support • May get much easier after Beta1

  39. Duplex services Demo

  40. 6 Silverlight and SEO

  41. What is SEO? From WikiPedia: Search engine optimization (SEO) is the process of improving the volume or quality of traffic to a web site from search engines via "natural" ("organic" or "algorithmic") search results. Typically, the earlier a site appears in the search results list, the more visitors it will receive from the search engine.

  42. Silverlight and search engines • Information contained in XAP file is not discoverable by a search engine  • Engine only cares about the source of the page • Consequence: no direct links to “pages” in SL your application

  43. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Silverlight Application</title> </head> <body> <div id="content"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2"> <param name="minRuntimeVersion" value="3.0.40305.0" /> <param name="source" value="ClientBin/MyApp.xap" /> <div class="down-level"> <h1>Down level content goes here. </h1> <p>Lorem ipsum dolor sit amet...</p> </div> </object> </div> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Silverlight Application</title> </head> <body> <div id="content"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2"> <param name="minRuntimeVersion" value="3.0.40305.0" /> <param name="source" value="ClientBin/MyApp.xap" /> <asp:ContentPlaceHolder ID="DownLevelContent" runat="server"/> </object> </div> </body> </html>

  44. Silverlight and SEO Linq-to-SQL Silverlight • Silverlight and ASP should talk to same logic • Can be achieved through RIA services • And its helper controls App logic: Domain-Service EntFW WPF ... ASP.NET

  45. <ria:SeoSilverlightApplication EnableGPUAcceleration="true" EnableUserState="false" ID="SilverlightApplication" Source="~/ClientBin/SilverlightStore.xap" MinimumVersion="3.0.40220.0" Width="100%" Height="640px" runat="server"> <PluginNotInstalledTemplate> ... <asp:ContentPlaceHolder ID="SilverlightDownLevelContent" runat="server" /> </PluginNotInstalledTemplate> </ria:SeoSilverlightApplication> Silverlight and SEO • Use a domain service (RIA services) <asp:DomainDataSource runat="server" ID="SitemapDataSource" DomainServiceTypeName="MyApp.Web.NorthwindDomainService" SelectMethod="GetSuperEmployees" />

  46. Silverlight and SEO Demo

  47. 7 VirtualEarth in Silverlight

  48. Use VirtualEarth in Silverlight • Available through Virtual Earth Silverlight Map Control (currently in CTP) • Allows embedding VE in SL apps • Important for online apps that require geographical information • Rich SDK

  49. Excuse me, but AJAX can do that also... • Pro’s of using VE in Silverlight • Rich, interactive mapping experience – zooming, panning • Opens up ability to do things that are not possible with Ajax map such as scaling images and video in a seamless manner • Development environment working with Managed Code and Visual Studio development, debugging tools, unit tests for our developers and our customer developers • Performance improvements regarding number of items to render on the map – pushpins (UIElements), polylines, polygons

  50. This is VE in SL Neat, isn’t it...? 

More Related