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. Question about MEFedMVVM

Question about MEFedMVVM

Scheduled Pinned Locked Moved WPF
question
16 Posts 6 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.
  • W Offline
    W Offline
    wasimsharp
    wrote on last edited by
    #1

    I have one main View inside that view i have multiple views(usercontrol) it is basically a Form to get the patient records. Now how i can pass the values of main ViewModel to the Child control ViewModels and then get the value back when user save the Form Main View?

    WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP

    M L P 3 Replies Last reply
    0
    • W wasimsharp

      I have one main View inside that view i have multiple views(usercontrol) it is basically a Form to get the patient records. Now how i can pass the values of main ViewModel to the Child control ViewModels and then get the value back when user save the Form Main View?

      WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Presumably you have static versions of your viewmodels so the state of the data has not changed when you move from one control to another. Therefore when you save the main VM all the other data is sitting there ready to be saved in the other VMs. This may break the MVVM model as the main VM is aware and uses the other VMs but as I'm not a purist so it does not bother me, I even have code in the codebehind (shock horror).

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • W wasimsharp

        I have one main View inside that view i have multiple views(usercontrol) it is basically a Form to get the patient records. Now how i can pass the values of main ViewModel to the Child control ViewModels and then get the value back when user save the Form Main View?

        WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP

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

        Don't know about MEF in particular, but how does it construct all the VMs to put 'inside' your main VM - The way I would do it (no Framework) would be to have references to each of the child VMs in my main VM (thus your main VM is truly describing the interaction) The alternative is to use a Controller (or some singleton class) to which every viewModel has a reference, and so can use this to communicate. This allows for better abstraction (e.g. your main VM asks the Controller "save the patient's data, because the Save button command has been raised by my View" The Controller either has direct access to the various data used by the other VMs, or has access to the other VMs from where it can obtain that data (e.g. VMBloodPressure, give me your data...)

        ___________________________________________ .\\axxx (That's an 'M')

        M W 2 Replies Last reply
        0
        • L Lost User

          Don't know about MEF in particular, but how does it construct all the VMs to put 'inside' your main VM - The way I would do it (no Framework) would be to have references to each of the child VMs in my main VM (thus your main VM is truly describing the interaction) The alternative is to use a Controller (or some singleton class) to which every viewModel has a reference, and so can use this to communicate. This allows for better abstraction (e.g. your main VM asks the Controller "save the patient's data, because the Save button command has been raised by my View" The Controller either has direct access to the various data used by the other VMs, or has access to the other VMs from where it can obtain that data (e.g. VMBloodPressure, give me your data...)

          ___________________________________________ .\\axxx (That's an 'M')

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          _Maxxx_ wrote:

          The alternative is to use a Controller

          Isn't that just moving the linkage one step away, the controller still needs to be aware of all the VMs Here is another thought, how about a message style where the main VM sends a message to save and the other VMs consume the message. All the VMs must subscribe to the message pump.

          Never underestimate the power of human stupidity RAH

          L 1 Reply Last reply
          0
          • M Mycroft Holmes

            _Maxxx_ wrote:

            The alternative is to use a Controller

            Isn't that just moving the linkage one step away, the controller still needs to be aware of all the VMs Here is another thought, how about a message style where the main VM sends a message to save and the other VMs consume the message. All the VMs must subscribe to the message pump.

            Never underestimate the power of human stupidity RAH

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

            Mycroft Holmes wrote:

            the controller still needs to be aware of all the VMs

            You're right - but I don't see not nuffin' wrong with that. IN the example cited by the OP I would probably have a property of VM1, VM2 etc. in my parent Vm - and access either methods, messages or events on or from them. The controller just allows for more consistent communication - your children VM ask the controller to do something (Hey controller, this data has changed, better handle that for me). The Controller then says to itself "Hey! this is a change in this data - I better let everyone know!" so it raises an event/sends a message/calls a method on a VM - whatever to let those interested parties know.

            Mycroft Holmes wrote:

            how about a message style where the main VM sends a message to save and the other VMs consume the message.

            Not sure that works - if a child Vm receives the message, how does it give the modified data back to the parent VM? I prefer the "I've changed something, please deal with it" paradigm, rather than the "Hey, have you changed anything? If so, give me the changes." paradigm. (Although, now I am thinking about at least implementing a "Some data has been changed by this VM" property in my base VM class - which in turn can send a message... So now the Parent VM can subscribe to any Child VM messages, and the message (at least potentially) can carry the modified data. Hmmm Child Vm1 changes the patient BP - it is now 'dirty' and sends a message to say so. Parent Vm0 has subscribed to the "BP Has Changed" message which carries with it a BP object. VM0 saves the data to the repository and sends out a "BP Has been Saved" message - which is (of course) subscribed to by the Vm1, which resets itself to "Clean" Sorry to think outloud in a reply - no sensible buggers at work to talk to!

            ___________________________________________ .\\axxx (That's an 'M')

            M 1 Reply Last reply
            0
            • L Lost User

              Mycroft Holmes wrote:

              the controller still needs to be aware of all the VMs

              You're right - but I don't see not nuffin' wrong with that. IN the example cited by the OP I would probably have a property of VM1, VM2 etc. in my parent Vm - and access either methods, messages or events on or from them. The controller just allows for more consistent communication - your children VM ask the controller to do something (Hey controller, this data has changed, better handle that for me). The Controller then says to itself "Hey! this is a change in this data - I better let everyone know!" so it raises an event/sends a message/calls a method on a VM - whatever to let those interested parties know.

              Mycroft Holmes wrote:

              how about a message style where the main VM sends a message to save and the other VMs consume the message.

              Not sure that works - if a child Vm receives the message, how does it give the modified data back to the parent VM? I prefer the "I've changed something, please deal with it" paradigm, rather than the "Hey, have you changed anything? If so, give me the changes." paradigm. (Although, now I am thinking about at least implementing a "Some data has been changed by this VM" property in my base VM class - which in turn can send a message... So now the Parent VM can subscribe to any Child VM messages, and the message (at least potentially) can carry the modified data. Hmmm Child Vm1 changes the patient BP - it is now 'dirty' and sends a message to say so. Parent Vm0 has subscribed to the "BP Has Changed" message which carries with it a BP object. VM0 saves the data to the repository and sends out a "BP Has been Saved" message - which is (of course) subscribed to by the Vm1, which resets itself to "Clean" Sorry to think outloud in a reply - no sensible buggers at work to talk to!

              ___________________________________________ .\\axxx (That's an 'M')

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              I go with the last scenario (after Hmmm) except (there is always an except) I would have vm1 (child) deal with it's own data (save to the DB) and tell VM0 that the data was saved. This assumes the database structure reflects the actual data where VM0 is the patient and VM1 is a BP record. VM0 may need to reload the list of BP records when told by VM1 that the record was saved and this would be prompted by the message pump.

              Never underestimate the power of human stupidity RAH

              L 1 Reply Last reply
              0
              • M Mycroft Holmes

                I go with the last scenario (after Hmmm) except (there is always an except) I would have vm1 (child) deal with it's own data (save to the DB) and tell VM0 that the data was saved. This assumes the database structure reflects the actual data where VM0 is the patient and VM1 is a BP record. VM0 may need to reload the list of BP records when told by VM1 that the record was saved and this would be prompted by the message pump.

                Never underestimate the power of human stupidity RAH

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

                Because this is a medical system (and the last system I developed was a medical system!) there may be requirements to save multiple uncommitted changes at one time; In fact in the system I developed, I did exactly what you are suggesting, but used a caching mechanism at the back-end so nothing was finally committed until the consultation was complete. It's amazing how much one can learn posting on CP! I'm in a situation where I am pretty much the sole developer, so don't have minds to bounce ideas off - every day I get home and completely change my MVVM application! :)

                ___________________________________________ .\\axxx (That's an 'M')

                1 Reply Last reply
                0
                • L Lost User

                  Don't know about MEF in particular, but how does it construct all the VMs to put 'inside' your main VM - The way I would do it (no Framework) would be to have references to each of the child VMs in my main VM (thus your main VM is truly describing the interaction) The alternative is to use a Controller (or some singleton class) to which every viewModel has a reference, and so can use this to communicate. This allows for better abstraction (e.g. your main VM asks the Controller "save the patient's data, because the Save button command has been raised by my View" The Controller either has direct access to the various data used by the other VMs, or has access to the other VMs from where it can obtain that data (e.g. VMBloodPressure, give me your data...)

                  ___________________________________________ .\\axxx (That's an 'M')

                  W Offline
                  W Offline
                  wasimsharp
                  wrote on last edited by
                  #8

                  @max thanks i think controler will help me.

                  WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP

                  1 Reply Last reply
                  0
                  • W wasimsharp

                    I have one main View inside that view i have multiple views(usercontrol) it is basically a Form to get the patient records. Now how i can pass the values of main ViewModel to the Child control ViewModels and then get the value back when user save the Form Main View?

                    WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP

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

                    Just spitballing here, but this situation is typically handled by the main VM knowing all of it's child VM's. I would probably look at using Reactive Extensions to observe the child VMs from the parent (as they should be firing property changed events when data changes), and the parent VM will react to the changes.

                    I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                    Forgive your enemies - it messes with their heads

                    My blog | My articles | MoXAML PowerToys | Onyx

                    J 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      Just spitballing here, but this situation is typically handled by the main VM knowing all of it's child VM's. I would probably look at using Reactive Extensions to observe the child VMs from the parent (as they should be firing property changed events when data changes), and the parent VM will react to the changes.

                      I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                      Forgive your enemies - it messes with their heads

                      My blog | My articles | MoXAML PowerToys | Onyx

                      J Offline
                      J Offline
                      Jammer 0
                      wrote on last edited by
                      #10

                      Nice ... I've not even heard of Reactive Extensions until I read this post. Thanks Pete! Hope you're well!

                      Jammer My Blog | Articles | DMon | SampleSort

                      P 1 Reply Last reply
                      0
                      • J Jammer 0

                        Nice ... I've not even heard of Reactive Extensions until I read this post. Thanks Pete! Hope you're well!

                        Jammer My Blog | Articles | DMon | SampleSort

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

                        Rx are really cool. I'm currently doing an article on using them with jQuery. I am well. How are you doing mate?

                        I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                        Forgive your enemies - it messes with their heads

                        My blog | My articles | MoXAML PowerToys | Onyx

                        J 1 Reply Last reply
                        0
                        • P Pete OHanlon

                          Rx are really cool. I'm currently doing an article on using them with jQuery. I am well. How are you doing mate?

                          I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                          Forgive your enemies - it messes with their heads

                          My blog | My articles | MoXAML PowerToys | Onyx

                          J Offline
                          J Offline
                          Jammer 0
                          wrote on last edited by
                          #12

                          Really good thanks fella. V. Busy! I've been and gone solo as a contractor! Pretty scary but going really well so far :-D

                          Jammer My Blog | Articles | DMon | SampleSort

                          P 1 Reply Last reply
                          0
                          • J Jammer 0

                            Really good thanks fella. V. Busy! I've been and gone solo as a contractor! Pretty scary but going really well so far :-D

                            Jammer My Blog | Articles | DMon | SampleSort

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

                            Good job. Where are you at?

                            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                            Forgive your enemies - it messes with their heads

                            My blog | My articles | MoXAML PowerToys | Onyx

                            J 1 Reply Last reply
                            0
                            • P Pete OHanlon

                              Good job. Where are you at?

                              I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                              Forgive your enemies - it messes with their heads

                              My blog | My articles | MoXAML PowerToys | Onyx

                              J Offline
                              J Offline
                              Jammer 0
                              wrote on last edited by
                              #14

                              I left Occam for 9 months, encountered utter hell at two companies during that time and was then offered work contracting for Occam again. Was a no-brainer although I'm not doing WPF right now, lots of ASP.NET, IIS and SQL. I really want to find a WPF contract after this one ends.

                              Jammer My Blog | Articles | DMon | SampleSort

                              S 1 Reply Last reply
                              0
                              • J Jammer 0

                                I left Occam for 9 months, encountered utter hell at two companies during that time and was then offered work contracting for Occam again. Was a no-brainer although I'm not doing WPF right now, lots of ASP.NET, IIS and SQL. I really want to find a WPF contract after this one ends.

                                Jammer My Blog | Articles | DMon | SampleSort

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

                                Don't be surprised at the lack of WPF jobs out there... it seems pretty rare to me. I was looking for a new gig cuz I was tiring of my current one and only saw 2 or 3 wpf ads over 6 months. People are still on MFC / Winforms, or just scrapping desktop and going web only. Guess I'll stick around then since I'm 100% WPF now :).

                                J 1 Reply Last reply
                                0
                                • S SledgeHammer01

                                  Don't be surprised at the lack of WPF jobs out there... it seems pretty rare to me. I was looking for a new gig cuz I was tiring of my current one and only saw 2 or 3 wpf ads over 6 months. People are still on MFC / Winforms, or just scrapping desktop and going web only. Guess I'll stick around then since I'm 100% WPF now :).

                                  J Offline
                                  J Offline
                                  Jammer 0
                                  wrote on last edited by
                                  #16

                                  Yeah, they are thin on the ground at the moment it appears. Where are you based?

                                  Jammer My Blog | Articles | DMon | SampleSort

                                  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