Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. MVVM pattern

MVVM pattern

Scheduled Pinned Locked Moved WPF
questionwpfwcfregexarchitecture
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    columbos14927
    wrote on last edited by
    #1

    Hello, Im already a bit familiar with the MVVM pattern, i still have a few question: 1.When i need Model class in addition to the ViewModel class? 2.If i use the Model class how do i connect the Model and the ViewModel(Binding,events), what is the right way? 3.Where to validate the data in the Model or the ViewModel class? I know that probabaly there isn't one way to go but what are the rules of thumb? Thanks.

    S 1 Reply Last reply
    0
    • C columbos14927

      Hello, Im already a bit familiar with the MVVM pattern, i still have a few question: 1.When i need Model class in addition to the ViewModel class? 2.If i use the Model class how do i connect the Model and the ViewModel(Binding,events), what is the right way? 3.Where to validate the data in the Model or the ViewModel class? I know that probabaly there isn't one way to go but what are the rules of thumb? Thanks.

      S Offline
      S Offline
      SledgeHammer01
      wrote on last edited by
      #2

      You *always* have a View, VM and Model. None of the parts are optional. View - Strictly 100% XAML (in fact, I prefer to delete the code behind entirely to prevent lazy programmers from uglifying the code). Some people will argue this is not a requirement, but IMO, it should be, it keeps the code cleaner. If you need to do something "complex" with a control, it shouldn't be done in the code behind, but rather broken out into a reusable UserControl. ViewModel - View binds to this class. Someone will now argue: but how do I set the VM since you have deleted the code behind? -- Answer: ViewLocator & DI. DI plays a second part in this class. It is used to inject the model into the constructor. ViewModel just wraps the Model with lazy load style properties and exposes commands that operate on the model, etc. Model - This is the API / storage layer of your objects. I like to break this out into its own assembly that a single programmer is managing for consistency. This is the *only* assembly that should even know what a database is. No database / persistence code of any kind is allowed anywhere else in the project. I like breaking the model out into its own assembly to keep things clean and in one place. Model should implement INPC and INCC.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups