1 / 38

WPF in 60 Seconds

WPF in 60 Seconds. So Much WPF - So Little Time Acing the WPF Interview ;). Overview. Windows Presentation Foundation. Purpose. Cover all the topics Give an idea of what you can do “oh yea, I’ve seen that” Don’t stress on learning any of it Hopefully create a useful resource.

alice
Download Presentation

WPF in 60 Seconds

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. WPF in 60 Seconds So Much WPF - So Little Time Acing the WPF Interview ;)

  2. Overview Windows Presentation Foundation

  3. Purpose • Cover all the topics • Give an idea of what you can do • “oh yea, I’ve seen that” • Don’t stress on learning any of it • Hopefully create a useful resource

  4. MS latest greatest Desktop UI Framework GUIs in .Net Best of Web, Patterns, and Previous UI Frameworks UI Framework Released in .Net 3.0 (Nov 2006) What is WPF

  5. Helpful Background • .Net • Used a control based UI Framework • VB6 • Windows Forms • ASP.Net • etc. • Familiar with HTML or XML

  6. Why is WPF GreatVisual Flexibility, Quick Results, Great Features • Auto Sizing, Auto Positioning Layout • Templating • Styles:  similar in concept to CSS:  allow skinning • Convenient (once you get the hang of it) Feature Rich Binding  • Triggers, Animation • Property Inheritance • Attached Properties • Bubbling & Tunneling Events • XAML is like HTML: its easy to create UIs visually and in markup • Rich UI Control: positioning, gradients, layering/opacity, etc. • Compositional Controls: (pictures in buttons, buttons in lists, no problem, lists in buttons, with pictures, etc.)

  7. WPF Vs. Silverlight • More features • Fewer restrictions • No band-aids or black holes • Desktop Only Devblog.Ailon.Org

  8. Tools • Visual Studio (2008, 2010) • Expression Blend (3/4) • ReSharper (auto adds references +++) • Snoop (WPF/free) • Silverlight Spy (paid)

  9. Core WPF

  10. Structure of a WPF App • Create with VS New WPF Application • App.XAML • StartupUri="Window1.xaml" • Resources • Subclass of Windows.Application  •  Window1.xaml • ctor: InitializeComponent(); • Subclass of Windows.Window 

  11. XAML All roads in WPF lead to XAML • Specialized XML • Creates Visuals like HTML  • Controls • Control Templates • Extensions for binding • Resource Dictionaries • Bindings normally defined here • Compiles to BAML

  12. Controls • Controls  • ItemsControl • "Single" Child Control • Button • CheckBox • Radio Button • ToggleButton • WPF Toolkit - CodePlex • out of band releases Panels - Multiple Children • Canvas • Grid • StackPanel • DockPanel • Wrap Panel • UniformGrid • VirtualizingPanel • VirtualizingStackPanel

  13. Grid • Common lightweight layout container • Column Width • Auto: fit to contents • *: take up the rest of the space • #*: proportional spacing

  14. Dependency Object / Property DO's have DP's Dependency Objects / Controls • For Binding Target in Controls  • INotifyPropertyChanged is code lighter for source binding in VMs • For Event Routing and Property Inheritance

  15. UI Features • Gradients • Geometries • Lines • CornerRadius • Transparency • Overlap (xaml order, z-order) • Rotation • Resize • Alignment: Left, Right, Top, Bottom, Stretch • Vector Graphics – resize looks great

  16. Preferred Pattern for XAML apps (builds on MVP, MVC, XYZ) Enhances testability, separation of concerns Controls are generally not named to favor binding MVP style is often used when needing to reference controls in code -- either publish a method on an interface of the view or make a control visible to code via a property.  Prime example XamDataGrid that has specific loading API that can't be bound MVVM (P)

  17. MVVM Details • Presenter • ViewModel • View • DataContext • Dispatcher

  18. Binding • Binding Failure • "Helpfully" doesn't crash your app or throw exception • See Results in the Output Window • Or it can truly fail silently: ex: mismatched IList<T> type will set null • FallbackValue -- rarely used  • Cheat Sheet • DataContext • ItemsSource Scenarios • Direct • Element • Ancestor • Multi-Level (target.element.element) Requriements For Handling Updates • INotify (ObservableCollection) • DependencyObject

  19. Resource Dictionary • x:Name • x:Key • StaticResource • DynamicResource • ResourceDictionary.MergedDictionaries • Control.Resources • Scoping, Cascade Effect

  20. Resources • Key • Style • TargetType • Setter, Property, Value • Brush, DataTemplate, etc.

  21. Advanced Binding • Fallback Value • PriorityBinding • Design Time ViewModel

  22. Styles (are not Templates) Though they can be skins.

  23. Templates DataTemplate ItemTemplate ControlTemplate Template Selectors vs. DataTemplates

  24. Context • UserControl – set datacontext of sub-element to UserControl (essentially code behind) • Template – uses instance binding • View – uses ViewModel because UserControl DataContext will be set to VM

  25. Triggers • DataTriggers • Property Triggers • Event Triggers • Multi-Triggers • http://www.wpftutorial.net/Triggers.html

  26. Converters • IValueConverter • IMultiValueConverter Need to put in Resource Dictionary Ex: Change VM data into UI friendly ex: • rename row 0 to row 1 • casing Can work as  • Template Selectors • Color Coders • etc. • CodePlex

  27. Commanding - Making it Go

  28. More Topics

  29. Data Validation IDataErrorInfo Requires annoyingly verbose binding syntax, but otherwise quite serviceable

  30. Logical and Visual Trees Snoop

  31. Threading • Important, but rarely an issue • Dispatcher • Task • RX

  32. Animations • DoubleAnimation: change a double value • Duration • RepeatBehavior

  33. Prism & Unity

  34. Prism / Unity: Composite Apps Composite Application Guidance for WPF and Silverlight • Regions • Event Aggregator • Catalog (IoC):  Unity Also:  logging interface Microsoft.Practices.ServiceLocation.dll. This assembly contains the Common Service Locator interface used by the Composite Application Guidance to provide an abstraction over Inversion of Control containers and service locators; therefore, you can change the container implementation with ease.

  35. Composite Bootstrapper WPF Hands-On Lab: Getting Started with the Composite Application Library • Shell.XAML • Regions:   • ContentControl or ItemsControl • Selector/TabControl  • Bootstrapper • CreateShell • GetModuleCatalog • App.OnStartup

  36. Prism Module • Module:  C# Class Library • Module:  IModule • Initialize • Views • each application UI piece is usually a UserControl • Populate Catalog with Modules • From code • most straightforward • possibly most common • From a XAML file • From a Configuration file • From a Directory

  37. Regions • Specified in XAML and IModules •  RegionManager Injected in Module Ctor • DemoModule(IRegionManager regionManager) • Initialize sets regions •    _regionManager.RegisterViewWithRegion("MainRegion", typeof(Views.HelloWorldView));

  38. Presenters, VMs, Base Classes, etc. • IModule.Initialize • Register type mappings – supports mocking view, vm • Create Presenter and register view into region: _regionManager.Regions[Regions.MainRegion].Add( _container.Resolve<CoolIntroPresenter>().View ); • Base interfaces and classes in WPF60.Infrastructure.CabSupport

More Related