introduction to wpf mvvm prism open discussion following n.
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction To WPF/MVVM/PRISM (Open Discussion Following) PowerPoint Presentation
Download Presentation
Introduction To WPF/MVVM/PRISM (Open Discussion Following)

Loading in 2 Seconds...

play fullscreen
1 / 29

Introduction To WPF/MVVM/PRISM (Open Discussion Following) - PowerPoint PPT Presentation

  • Uploaded on

Introduction To WPF/MVVM/PRISM (Open Discussion Following). What is WPF. Successor To Win Forms (Desktop) Builds Aesthetically Pleasing Interfaces (but much more than just a “pretty face”….more on this later) Segue To Silverlight Web(subset of WPF)

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Introduction To WPF/MVVM/PRISM (Open Discussion Following)' - erno

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
what is wpf
What is WPF
  • Successor To Win Forms (Desktop)
  • Builds Aesthetically Pleasing Interfaces (but much more than just a “pretty face”….more on this later)
  • Segue To Silverlight Web(subset of WPF)
  • Similar to ASP.NET IDE to Create a WPF Project
    • .xaml file~ (similar to) .aspx file (design and source window with “xaml” namespace objects instead of html namespace, pronounced “zammel”)
    • .xaml.cs file~ .aspx.cs file (code behind)
    • Drag and drop WYSIWYG from Toolbox onto .xaml file (has design and source views)
    • Entire WYSWG design process similar to ASP.NET (event handlers, etc)
    • “Resources” ~ CSS
    • Heart of WPF is Resources, Data Binding, Triggers, Control Templates, and Data Templates you create for designing the UI and binding to your data
    • In conclusion…..To Create a WPF application it is VERY similar to creating an ASP.NET application, only html namespace and objects are replaced by “xaml” namespace and objects. and you create Control Templates (change the visual part of a control) and Data Templates (to control the data that a Control displays)
what is wpf1
What Is WPF
  • Visual Studio WPF IDE (blankWpfProj)
  • show MainWindow similar to WinForm
  • show .xaml view (aspx like)
  • show.xaml.cs code behind
  • show tool box
  • Dem drag and drop button, textbox
  • Dem highlighting in Design and xml
  • Dem double clicking button=>event handler code
  • In conclusion…designing the Visual is simiar to a combination of WinForms and….HOWEVER, instead of setting visual element values like txtBox.Text = “whatever” WPF uses the concept of “Data Binding”
what is wpf2
What Is WPF
  • WPF is all about DATA BINDING and DataContext (binding context)
  • You bind your Visual Elements to your code (or other controls) and Vice-Versa via dependency properties (public properties of the View or ViewModel)
  • Example…SimpleWpfExample
  • Show txtbox databinding
  • Dem running program and showing how visual txtbox gets its values set via PUBLIC PROPERTY
  • Dem entering different value and showing how value in codebehind gets changed
  • Show how “Get Product” button event handler is bound to “GetProductCommand”. You add event delegation code (not shown) to handle the event to delegate the event handler to WHEREVER you specify it to be (e.g., the ViewModel in MVVM)
what is wpf3
What Is WPF
  • More on Binding
  • Regardless of what element you are binding and the nature of your data source, each binding always follows the model illustrated by the figure:
  • As illustrated by the above figure, data binding is essentially the bridge between your binding target and your binding source. The figure demonstrates the following fundamental WPF data binding concepts:
  • Typically, each binding has these four components: a binding targetobject, a targetproperty, a binding source, and a path to the value in the binding source to use. For example, if you want to bind the content of a TextBox to the Nameproperty of an Employeeobject, your target object is the TextBox, the target property is the Text property, the value to use is Name, and the source object is the Employee object.
  • The targetproperty must be a dependency property. Most UIElement properties are dependency properties and most dependency properties, except read-only ones, support data binding by default. (Only DependencyObject types can define dependency properties and all UIElements derive from DependencyObject.)
  • Although not specified in the figure, it should be noted that the binding source object is not restricted to being a custom CLR object. WPF data binding supports data in the form of CLR objects and XML. To provide some examples, your binding source may be a another UIElement, any list object, a CLR object that is associated with ADO.NET data or Web Services, or an XmlNode that contains your XML data. For more information, see Binding Sources Overview.
what is wpf4
What Is WPF
  • Binding Types…show Binding cheat sheet.pdf
what is wpf5
What Is WPF
  • More Complex Code Example
  • What is it?....Grid, List, Image?
what is wpf6
What is WPF
  • Actually, it’s a Button.
  • Note how controls can be
  • Nested to any level
why use wpf
Why Use WPF
  • More than just a “pretty face”
    • WPF lets you use a consistent development model to build applications (desktop AND Web) that run in more environments (even UNIX and Mac), on more hardware, using more graphical tools (two and three dimensional graphics, high-resolution VECTOR graphics that draw lines and curves rather than bitmaps), and cutting-edge animation, audio and video.
    • Microsoft is pushing it (or at least was) .
    • Perhaps the most important reason is that makes you more employable, especially if you are a Contractor. I know another technology to keep me employed.
why use wpf1
Why Use WPF
  • Example 1
why use wpf2
Why Use WPF
  • Example 2
why use wpf3
Why Use WPF
  • Example 3
what is mvvm
What Is MVVM
  • Stands for Model-View-ViewModel
  • Similar to the MVP pattern where ViewModel replaces the P (Presenter)
  • It essentially provides for “separation of concerns”, i.e., the visual part of the application is not tightly coupled to the data and business rules of the application. Thus the data and Business rules can theoretically be changed without affecting the View.
  • It essentially accomplishes this by having no “code behind” in the View
  • Application data and business rules reside in the Model, the ViewModel acts as an intermediary between the Model and View and in WPF the View is populated with public properties of the ViewModel via WPF data binding. Again, there is no code behind in the View.
what is mvvm1
What Is MVVM

MVVM Data Flow - Model

  • Model – contains the Application Data from Database or whatever
    • Communicates only with the ViewModel
    • Updates the ViewModel data whenever the data changes
    • ViewModel updates the Model data whenever the data changes as a result of UI actions (or whatever)
    • Also contains the Business Rules of the application
what is mvvm2
What Is MVVM

MVVM Data Flow - ViewModel


  • Sends Model data (via Data Binding …WPF is ALL about Data Binding) to the View
  • Updates View data via PropertyChanged events
  • Updates Model data that occur as the result of UI events (or whatever) back to the Model
what is mvvm3
What Is MVVM

MVVM Data Flow – View

  • Contains NO CODE BEHIND
  • Gets data via data binding on observable (public) properties of the ViewModel
  • Handles UI events (Button Pressed, etc) via Commands, etc, sent to the ViewModel who then handles the event processing code
  • View data is updated via PropertyChanged events of the VM
why mvvm
  • Separates the View from the Data and Business Rules of the application. If the Business Rules change the View may or may not have to be changed and vice-versa
  • Allows for the View to be handed off to Visual Designers (who are obviously well versed in WPF) while more traditional developers who are less WPF aware can develop the Business Rules of the application
  • Allows for automated testing with no user interaction as the UI events of the View can be simulated
  • Go here for a better understanding of why to us MVVM
what is prism

PRISM is a set of DLL’s AND Source Code available for free and is Microsoft’s “Toolkit” for doing WPF MVVM. It automates much of the MVVM plumbing (another good toolkit for learning the MVVM pattern that is not as automated is the MVVM Light Toolkit at

One of it’s main’s main advantage is that it automates much of the MVVM pluming via “Inversion Of Control” (objects are passed into other objects that use them rather than instantiating them internally) and “Dependency Injection” (automatically doing IOC)

The other main advantage is that it creates the concept of “Modules” which can be independently developed (by other developers, groups or even companies) and tested. These modules communicated with each other via the PRISM’s “EventAggragator” via “Publish” and “Subscribe” messaging.

what is prism1
  • Inversion Of Control Example
  • Now the Client can use ANY spell checker that derives from interface ISpellChecker
what is prism2
  • Dependency Injection is what PRISM does automatically “behind the scenes”. It means that this is done without the object intervention, usually by a framework component (PRISM) that passes constructor parameters and set properties
  • This leads to somewhat automatic MVVM “pluming”
what is prism3
  • Top Level Diagram
what is prism4
  • More detailed
what is prism6
  • Code Sample
  • C:\_IT\__VisualStudio2010\Projects\SilvelightPrismDemo\SilvelightPrismDemo\PrismSample\PrismSample.sln
why prism
  • Handles MVVM “pluming” automatically
  • Can have independently developed “Module” DLLS
  • Has all the advantages of MVVM (automated testing, etc)
learning curve for wpf mvvm prism
Learning Curve For WPF/MVVM/PRISM
  • My experience to Learn WPF/MVVM/PRISM…….
  • 60 % WPF
  • 20% MVVM
  • 20% PRISM
  • Others Experiences?
  • WPF 4 Unleashed – SAMS
  • WPF C# Programming – apress
  • Developers Guide To Microsoft PRISM 4 – Microsoft….all the info is definitely in there, just hard to find at times….has many good examples and has complete sample VS project code.
open discussion
Open Discussion
  • Questions?
  • Experienced WPF users feel free to answer, add to answer, or share their experiences with WPF, MVVM or PRISM