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. WPF and MVVM pattern question

WPF and MVVM pattern question

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpdesignregex
9 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.
  • B Offline
    B Offline
    babongita
    wrote on last edited by
    #1

    I am trying to follow Karl Shifflett or Josh Smith MVVM pattern but I don't fully comprehend how I can make this happen. And I am hoping that I can get some help here. I have an Object_A with some attributes, and an ObservableCollection. Then in the UI I have a "view" of the attributes of Object_A, with a list box below which has the ObservableCollection. What I want to be able to do is to be able to edit the attributes of the selected item in the list box and I want to be able to add a new Object_A if the "Add" button is clicked. This is where I get confused, because it is technically not bound any longer to the object in the list box it is it's own object that needs to be inserted into the ObservableCollection. I have two separate views and two view-models, and the "Add" button on the Object_A view-model, raises an event and passes the new Object A to the View-Model for the collection of Object_A, and if I set a break point and look at the Collection View-Model's ObservableCollection which the UI is bound to the ObservableCollection shows that the count has changed, but the UI doesn't reflect this change, is like the UI doesn't get notified that the ObservableCollection has changed and the List box should be updated. What should I be doing to get the UI to "refresh" itself when a new Object_A is being inserted into the ObservableCollection?

    P 1 Reply Last reply
    0
    • B babongita

      I am trying to follow Karl Shifflett or Josh Smith MVVM pattern but I don't fully comprehend how I can make this happen. And I am hoping that I can get some help here. I have an Object_A with some attributes, and an ObservableCollection. Then in the UI I have a "view" of the attributes of Object_A, with a list box below which has the ObservableCollection. What I want to be able to do is to be able to edit the attributes of the selected item in the list box and I want to be able to add a new Object_A if the "Add" button is clicked. This is where I get confused, because it is technically not bound any longer to the object in the list box it is it's own object that needs to be inserted into the ObservableCollection. I have two separate views and two view-models, and the "Add" button on the Object_A view-model, raises an event and passes the new Object A to the View-Model for the collection of Object_A, and if I set a break point and look at the Collection View-Model's ObservableCollection which the UI is bound to the ObservableCollection shows that the count has changed, but the UI doesn't reflect this change, is like the UI doesn't get notified that the ObservableCollection has changed and the List box should be updated. What should I be doing to get the UI to "refresh" itself when a new Object_A is being inserted into the ObservableCollection?

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

      Well - if you add the object to the ObservableCollection, the UI will be updated for you automatically (assuming you've used the appropriate bindings). How have you set up the Mode on your listbox? That's possibly where you are having a problem - try setting it to OneWay.

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

      My blog | My articles | MoXAML PowerToys

      B 1 Reply Last reply
      0
      • P Pete OHanlon

        Well - if you add the object to the ObservableCollection, the UI will be updated for you automatically (assuming you've used the appropriate bindings). How have you set up the Mode on your listbox? That's possibly where you are having a problem - try setting it to OneWay.

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

        My blog | My articles | MoXAML PowerToys

        B Offline
        B Offline
        babongita
        wrote on last edited by
        #3

        I was thinking it could be something with me overriding the OnCollectionChanged, but when I took that completely out, it still didn't work so I was thinking that it was something else.

        P 1 Reply Last reply
        0
        • B babongita

          I was thinking it could be something with me overriding the OnCollectionChanged, but when I took that completely out, it still didn't work so I was thinking that it was something else.

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

          If I could see the markup, it will be easier to get an idea.

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

          My blog | My articles | MoXAML PowerToys

          B 1 Reply Last reply
          0
          • P Pete OHanlon

            If I could see the markup, it will be easier to get an idea.

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

            My blog | My articles | MoXAML PowerToys

            B Offline
            B Offline
            babongita
            wrote on last edited by
            #5

            Here is the XAML IsSynchronizedWithCurrentItem="True" Grid.Row="1" ItemsSource="{Binding Path=ReportScreens}" ItemTemplate="{DynamicResource ScreenTabScreen}" Margin="10,0,10,10"> And I can email any/all of the code for these areas if you would like.

            P 2 Replies Last reply
            0
            • B babongita

              Here is the XAML IsSynchronizedWithCurrentItem="True" Grid.Row="1" ItemsSource="{Binding Path=ReportScreens}" ItemTemplate="{DynamicResource ScreenTabScreen}" Margin="10,0,10,10"> And I can email any/all of the code for these areas if you would like.

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

              Sure - my email is pete dot ohanlon at gmail dot com.

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

              My blog | My articles | MoXAML PowerToys

              1 Reply Last reply
              0
              • B babongita

                Here is the XAML IsSynchronizedWithCurrentItem="True" Grid.Row="1" ItemsSource="{Binding Path=ReportScreens}" ItemTemplate="{DynamicResource ScreenTabScreen}" Margin="10,0,10,10"> And I can email any/all of the code for these areas if you would like.

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

                Hi - I'm still waiting for the code. If you want to zip your project up, I'll take a look at it later on. My email is in my earlier post.

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

                My blog | My articles | MoXAML PowerToys

                B 1 Reply Last reply
                0
                • P Pete OHanlon

                  Hi - I'm still waiting for the code. If you want to zip your project up, I'll take a look at it later on. My email is in my earlier post.

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

                  My blog | My articles | MoXAML PowerToys

                  B Offline
                  B Offline
                  babongita
                  wrote on last edited by
                  #8

                  Sorry, Pete I did send you the code on Wednesday I used pete.ohanlon@gmail.com. I resent the code again just now, it will come from zoey.babongita@gmail.com. If you don't get it soon, please let me know, You should have two emails now, the first one being a few classes, and the second one being the entire solution. Pick your poison. Thanks

                  P 1 Reply Last reply
                  0
                  • B babongita

                    Sorry, Pete I did send you the code on Wednesday I used pete.ohanlon@gmail.com. I resent the code again just now, it will come from zoey.babongita@gmail.com. If you don't get it soon, please let me know, You should have two emails now, the first one being a few classes, and the second one being the entire solution. Pick your poison. Thanks

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

                    I've got them now. It looks like the original mail was picked up by the spam filter (though I'm not sure why). I'll take a look at them when I get home tonight.

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

                    My blog | My articles | MoXAML PowerToys

                    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