views:

89

answers:

1

Hi, I'm using MVP in WPF and I came across a design doubt and I would to get your opinion on this:

At some point I need to refresh my view and perform the same initial queries, like when the view was loading. The view's DataContext is my presenter and I have a couple of collections and other variables that are bound to the view. When I need to refresh the view, I'm clearing the collections and the variables and setting the DataContext to null. After that I fetch new data, populate the collections and set the DataContext. Is this the best way to achieve this?

The issue with this, is that i'm affraid that when my app grows bigger I forget to reset some variable...the ideal would be to reload the view again in some way without having to worry with the variables I have.

Best regards.

A: 

Jay, the design philosophy for WPF is very data driven. Given that fact, I would suggest that you don't need to set the DataContext to null or reload the view. Instead, you could use observable collections or implement INotifyPropertyChanged in your DataContext object to alert the view to data being cleared and refreshed.

Ed Gonzalez
Hey Ed, I get your idea, and I agree (in part at least).The thing is, I have lots of variables bound to the view so I would have to reset all of them manualy (the propertychanged takes care of the UI update). Clearing my collections (assuming they are Observable) would clean the textblocks values and ComboBoxes SelectedItems? That could serve my purposes...I didn't use Observ. collections because I didn't want to build them item by item (for my situation), because of the overhead...Building a couple of Obs. collections of around 10 items each will have a significant impact?
Jay
Jay, that may be an area where you have to do some performance testing. An idea: You could use collections that implement IList, instead of ObservableCollections, then use INotifyPreportyChanged after all items were added/removed. This way you only get the update hit after you added everything, not once per item.
Ed Gonzalez