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. ViewModel musings

ViewModel musings

Scheduled Pinned Locked Moved WPF
csharpwpfcomtoolsregex
4 Posts 3 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
    ColinM123
    wrote on last edited by
    #1

    Ramble I've been looking at using the View-ViewModel-Model pattern in WPF & Siverlight for some small apps. Often I find the ViewModel is very similar to the Model in my simple apps, but maybe just a few more view specific properties. Wrapping my Model class in a ViewModel is sometimes problematic. Say we have an Employee Class and we want to add a IsSelected property so it can be used in the View. If we create a ViewModel Employee class and add the new IsSelected property all is okay, except.... If any other class, say Company.GetEmployees() returns a List, then I have to write another wrap to enumerate through the results and transform Employee to ViewModelEmployee. Possible solution? Use Extension Methods (don't have Extension Properties) Then I can just add GetIsSelected, SetIsSelected methods to the base Employee class. Using an ObjectDataProvider (don't think this is in Silverlight) we can access the GetIsSelected method, using Bindings similar to properties. At least that's what I'm thinking haven't tried this out yet! /Ramble

    Online Guitar Tools

    L 1 Reply Last reply
    0
    • C ColinM123

      Ramble I've been looking at using the View-ViewModel-Model pattern in WPF & Siverlight for some small apps. Often I find the ViewModel is very similar to the Model in my simple apps, but maybe just a few more view specific properties. Wrapping my Model class in a ViewModel is sometimes problematic. Say we have an Employee Class and we want to add a IsSelected property so it can be used in the View. If we create a ViewModel Employee class and add the new IsSelected property all is okay, except.... If any other class, say Company.GetEmployees() returns a List, then I have to write another wrap to enumerate through the results and transform Employee to ViewModelEmployee. Possible solution? Use Extension Methods (don't have Extension Properties) Then I can just add GetIsSelected, SetIsSelected methods to the base Employee class. Using an ObjectDataProvider (don't think this is in Silverlight) we can access the GetIsSelected method, using Bindings similar to properties. At least that's what I'm thinking haven't tried this out yet! /Ramble

      Online Guitar Tools

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      To solve your very specific problem, use the OptionViewModel class from this article: http://www.codeproject.com/KB/WPF/ExploringWPFMVVM.aspx[ href="http://www.codeproject.com/KB/WPF/ExploringWPFMVVM.aspx" target="_blank" title="New Window">^] Give yourself more time and understand "why" you need a ViewModel. Writing some small aps is a great idea. Don't forget to write Unit Tests for those apps. ViewModel's make writing unit tests easy.

      Cheers, Karl » CodeProject 2008 MVP, CodeProject 2009 MVP My Blog | Mole's Home Page | XAML Power Toys Home Page

      Just a grain of sand on the worlds beaches.

      P C 2 Replies Last reply
      0
      • L Lost User

        To solve your very specific problem, use the OptionViewModel class from this article: http://www.codeproject.com/KB/WPF/ExploringWPFMVVM.aspx[ href="http://www.codeproject.com/KB/WPF/ExploringWPFMVVM.aspx" target="_blank" title="New Window">^] Give yourself more time and understand "why" you need a ViewModel. Writing some small aps is a great idea. Don't forget to write Unit Tests for those apps. ViewModel's make writing unit tests easy.

        Cheers, Karl » CodeProject 2008 MVP, CodeProject 2009 MVP My Blog | Mole's Home Page | XAML Power Toys Home Page

        Just a grain of sand on the worlds beaches.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Great answer Karl. Like it.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        My blog | My articles | MoXAML PowerToys

        1 Reply Last reply
        0
        • L Lost User

          To solve your very specific problem, use the OptionViewModel class from this article: http://www.codeproject.com/KB/WPF/ExploringWPFMVVM.aspx[ href="http://www.codeproject.com/KB/WPF/ExploringWPFMVVM.aspx" target="_blank" title="New Window">^] Give yourself more time and understand "why" you need a ViewModel. Writing some small aps is a great idea. Don't forget to write Unit Tests for those apps. ViewModel's make writing unit tests easy.

          Cheers, Karl » CodeProject 2008 MVP, CodeProject 2009 MVP My Blog | Mole's Home Page | XAML Power Toys Home Page

          Just a grain of sand on the worlds beaches.

          C Offline
          C Offline
          ColinM123
          wrote on last edited by
          #4

          Thanks Karl, looking forward to your MVVM series! I just noticed this article in the updates which is pretty much what I was thinking about. http://www.codeproject.com/KB/WPF/WPF-Presentation-Models.aspx[^]

          Online Guitar Tools

          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