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. An MVVM way to know when a database update is complete in order to navigate to another page.

An MVVM way to know when a database update is complete in order to navigate to another page.

Scheduled Pinned Locked Moved WPF
databasewpfbusinessarchitecturetutorial
7 Posts 5 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.
  • T Offline
    T Offline
    ToddHileHoffer
    wrote on last edited by
    #1

    So, I have everything completed with no code in the code behind. I have everything separated. How should my view model notify the view that the database update has worked? Any thoughts or examples on how to do this?

    I didn't get any requirements for the signature

    P L A M 4 Replies Last reply
    0
    • T ToddHileHoffer

      So, I have everything completed with no code in the code behind. I have everything separated. How should my view model notify the view that the database update has worked? Any thoughts or examples on how to do this?

      I didn't get any requirements for the signature

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

      You could simply add a dirty flag and bind to this.

      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

      1 Reply Last reply
      0
      • T ToddHileHoffer

        So, I have everything completed with no code in the code behind. I have everything separated. How should my view model notify the view that the database update has worked? Any thoughts or examples on how to do this?

        I didn't get any requirements for the signature

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

        Your VM needs to expose some property that indicates success or failure. You might need a converter because there are three or four states you're talking about: 1. Don't have a pending update 2. Have a pending update 3. Update failed 4. Update passed (2. is only appropriate for asynchronous updates) So your VM has a property that starts off with a value 1. When the 'save' command is triggered, it is set to 2. When the results of the Save are returned t is set to 3 or 4 respectively. You could 'merge' this with any process you are using to enable/disable the Save button - so add another state ... 0. Nothing To Save

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

        1 Reply Last reply
        0
        • T ToddHileHoffer

          So, I have everything completed with no code in the code behind. I have everything separated. How should my view model notify the view that the database update has worked? Any thoughts or examples on how to do this?

          I didn't get any requirements for the signature

          A Offline
          A Offline
          Abhinav S
          wrote on last edited by
          #4

          Bind the status to a textblock and create a property for it in your view model (assuming everything is bound to the view model). Once your async web service comese back from the server, fire an action to get to the view model and then let INotifyPropertyChanged take over to update the status.

          The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

          T 1 Reply Last reply
          0
          • A Abhinav S

            Bind the status to a textblock and create a property for it in your view model (assuming everything is bound to the view model). Once your async web service comese back from the server, fire an action to get to the view model and then let INotifyPropertyChanged take over to update the status.

            The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

            T Offline
            T Offline
            ToddHileHoffer
            wrote on last edited by
            #5

            This is what I did. I guess the user will have to click a link to navigate, or I can put that in the code behind. Thanks for the reply.

            I didn't get any requirements for the signature

            A 1 Reply Last reply
            0
            • T ToddHileHoffer

              This is what I did. I guess the user will have to click a link to navigate, or I can put that in the code behind. Thanks for the reply.

              I didn't get any requirements for the signature

              A Offline
              A Offline
              Abhinav S
              wrote on last edited by
              #6

              Strange. You should not need to - are the datacontext's correct?

              The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

              1 Reply Last reply
              0
              • T ToddHileHoffer

                So, I have everything completed with no code in the code behind. I have everything separated. How should my view model notify the view that the database update has worked? Any thoughts or examples on how to do this?

                I didn't get any requirements for the signature

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

                We use the MVVMlight framework from Galasoft, it has a messaging construct. In the completed method we send the name of the method via a Completed message pump, the relevant view or viewmodel subscribes to the Completed message, checks the message content and takes action as appropriate. We use a VERY simplified structure, I know it can get a lot more complex but this meets our current needs. However I rarely (never) use it to navigate as the datacontext generally meets our needs (data refreshes after the call and updates the UI via onpropertychanged)

                Never underestimate the power of human stupidity RAH

                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