WPF and MVVM pattern question
-
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?
-
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?
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
-
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
-
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.
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
-
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
-
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.
Sure - my email is pete dot ohanlon at gmail dot com.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
-
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.
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
-
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
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
-
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
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