270 likes | 541 Views
Windows Presentation Foundation ("Avalon"): Using Application Services. Lauren Lavoie PRS314 Program Manager Microsoft Corporation llavoie@microsoft.com http://laurenlavoie.com/avalon. Outline. Creating a smart client application Demo: Chefalon Smart client app challenges
E N D
Windows Presentation Foundation ("Avalon"): Using Application Services Lauren Lavoie PRS314 Program Manager Microsoft Corporation llavoie@microsoft.com http://laurenlavoie.com/avalon
Outline • Creating a smart client application • Demo: Chefalon • Smart client app challenges • Demo: Runtime management and resources • Demo: Storage and user experience model • Creating a rich browser application • Web application challenges • Web Browser Applications • Demo: Moving Chefalon into the browser • Q&A
Application Model Challenges • App frameworks are restrictive • Infrastructure for user experience models doesn’t exist • Platforms don’t provide good metaphors for app-level management
App State and Runtime Management • <Application> is the base class for an app • Starts and stops the application • Resources • A place for your app-global state • Property bag • Subclassing • Events rather than WM_* messages • Activation, deactivation • App exit, session ending • Window management
Application ResourcesDeclarative model for loading resources Loose files in app dir Resources in the app <Frame Source=“Mushroom.xaml” /> <Frame Source=“Salmon.xaml” /> Navigate(new Uri(“Mushroom.xaml”, UriKind.RelativeOrAbsolute)); Navigate(new Uri(“Salmon.xaml”, UriKind.RelativeOrAbsolute)); From site of origin In another assembly <Frame Source= “Food;Component/Egg.xaml” /> <Frame Source= “pack://siteoforigin:,,Quiche.xaml” /> Navigate(new Uri(“Food;Component/Egg.xaml”, UriKind.RelativeOrAbsolute)); Navigate(newUri(“pack://siteoforigin:,,Quiche.xaml”, UriKind.RelativeOrAbsolute));
Persistent Storage and Settings Cookies Application File System Isolated Storage Windows Registry .config
User Experience ModelFlavors of Windows Applications SDI / Dialog MDI Structured Navigation Navigation-based SDI Navigation-based MDI
User Experience ModelDialog-Based SDI • Use Windows, Dialogs, and Controls • May manage multiple windows in the same app • Features often surfaced to users through menus // Window1.xaml <Window x:Class=“App.Window1” ...> <DockPanel> <Menu> <!-- define menu here --> </Menu> <!-- controls and UI here --> </DockPanel> </Window> Great UX paradigm for simple or frequent tasks The user is in control
User Experience ModelBasic Navigation // Page1.xaml <Page x:Class=“App.Page1” ...> <TextBlock> <Hyperlink NavigateUri=“page2.xaml”>Go To Page 2</Hyperlink> </TextBlock> </Page> // Page2.xaml <Page x:Class=“App.Page2” ...> <TextBlock>This is Page 2 </TextBlock> </Page> Use Pages, Hyperlinks, Frames NavigationWindow created implicitly when StartupUri is set Navigation UI and history provided out of the box Great UX paradigm for tasks that are unfamiliar to users or involve several steps User may be led through steps or can safely explore
Problems with Simple Navigation Hyperlink == GOTO http://www.site.com/login.aspx?param1=hello&back=homepage.aspx
Structured NavigationSolving the Problems with Simple Navigation PageFunctions == function calls
User Experience ModelStructured Navigation // PF1.xaml <PageFunction x:Class=“App.PF1” x:TypeArguments=“Int32” ...> <Grid> ... </Grid> </PageFunction> // Page1.xaml.cs PF1 pf = new PageFunction1(); pf.InitializeComponent(); pf.Return += new ReturnEventHandler<int>(pf_Return); this.NavigationService.Navigate(pf); • Use PageFunction • PageFunction is called like a function, returns result to caller • Upon finish, returns the user to the calling page • May create sophisticated topologies Great UX paradigm for tasks involving a sophisticated flow of steps The app drives the user
Web Application Challenges • Vastly different programming models for Web and Windows apps • Making highly interactive, personalized Web apps is hard • Creating interactive apps often requires a tradeoff with security
Web Browser Applications (WBA)Moving WPF to the Web • Run in a security sandbox • Have no security or installation prompt • Are not installed • No Start Menu or Add/Remove Programs presence • Use ClickOnce for deployment • Run in the browser • Familiarity of web browsing • Are “online only” apps
Web Browser ApplicationsThe Security Sandbox • Web Browser Apps run in a sandbox • Code Access Security (CAS) • Permission-based sandbox • Applications are limited by deployment zone • App is granted specific set of permissions • Attempt to use features not enabled in sandbox raises SecurityException Full Trust (Standalone Apps) Secondary Windows, File System Access, WCF, Registry Access… Internet Zone (WBA) Isolated Storage, Site of Origin Access, Printing, 3D, Flow, Animation…
Web Browser ApplicationsThe defense-in-depth foundation • Code Access Security – 1st line of defense • Security Transparent / Security Critical • IE7 Protected Mode on Windows Vista • On other platforms, remove IE6’s admin token • Out of process from browser • Hard isolation boundary • Trustworthy Computing best practices • Threat models, code reviews, static tools
Web Browser ApplicationsConverting a desktop app to a web app • Specify “Web Browser Application” • Using the Visual Studio 2005 template • By setting 3 properties in your project file • Remove non-sandbox friendly code • Conditional blocks • Runtime checks • // Get AppDomain’s permission set • PermissionSet aDPermSet = AppDomain.CurrentDomain.DefaultGrantSet.ApplicationTrust.PermissionSet; • PermissionSet permSet = new PermissionSet(); • permSet.AddPermission(new • UIPermission(UIPermissionWindow.AllWindows); • // Set cache bit • _bindToWindow = !permSet.IsSubsetOf(aDPermSet); • #if (WBA) • // Write to iso storage • #else • // Write to file system • #endif
Practical Web Browser ApplicationsMigrating or integrating with your existing site • Multiple renderings – WPF for the premium experience • Sniffing the UserAgent string • Leveraging your existing content • Hosting HTML in WPF • Hosting WPF in HTML • Interop with an existing backend • Using cookies • Use XSLT to transform to loose XAML
Web Browser Apps and Installed AppsTwo great flavors of WPF hosting • Web Browser Apps • Safe and easy for users • Seamless browser experience – no prompts! • Power of the platform on the Web • Installed Apps • Can use non-sandbox features • Can create immersive experiences • Can provide offline support • “Sticky” desktop presence
Summary • WPF provides options for app management • Low policy primitives for system and data management • Built-in infrastructure for common user experience models • Web Browser Applications give you the power of WPF on the Web • Runs in a security sandbox • Seamless browser experience
Community Resources • At PDC • For more information, go see • PRS330: Creating Rich Content Experiences in Your Applications • FUN222: Installation Technologies for Windows Vista • Labs: PRSHOL09, PRSHOL10 • Ask The Experts • Track lounge: I’ll be there Thu 9:30-12:30 • After PDC • If you missed this related session, watch on the DVD • PRS313: Integrating with Your Win32/MFC Application • http://laurenlavoie.com/avalon • MSDN dev center: http://msdn.microsoft.com/smartclient/ • Channel 9 tag: http://channel9.msdn.com/tags/Avalon
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.