Reputation: 843
I have a window (Windows form ) where i have two WPF user controls apart from other controls.
One user control has list of items (names) with available checkbox along side. Other one has a description of the items (Some pictures and other details).
Both user controls have their view models
The user can select and unselect checkboxes in the first user control. Based on his selection, the items details gets added/removed to the 2nd user control.
We are getting all data from the database. So initally to populate we retreive the data from database. We also store the select/unselect of the user back to database. The 2nd user control also needs to refresh data from database. We donot store anything on memory.
What needs to happen is that when user selects/unselects in first usercontrol, it should get added into the 2nd user control. So the operation are : Save or delete selection into database --> Send a request to 2nd user control to refresh it's collection reading the data from database.
I am using the Dispatcher object of the first usercontrol (invoked from a eventhandler in 1st user control view model) and invoking a method on Parent Form (the Windows container form). This parent form then invokes the refresh of the 2nd user control view model that refreshes the 2nd user control.
The problem is that the UI of the 1st user control freezes till this whole process is completed. What i want instead is that the UI of 1st user control not to freeze. The reason is that the UI of 1st control need not wait for operation in 2nd user control to be updated. The 2nd View refresh can be queued.
So basically what i want is when user selects/unselect checkboxes is just send the notification (for refresh of 2nd user control) and continue with my user control and not wait.
I tried Background worker but nothing seems to work.
Any help is appreciated.
Upvotes: 2
Views: 383
Reputation: 7719
if you are able to create a ViewModel instance that is used by both Views, You can probably avoid having to do any of the notification coding.
If you need to keep the VM's seperate, then if you have some sort of event mechanism in your code will do the trick. For instance if you are using Unity, the EventAggregator can be used to do the notification, this will bypass the parent form and your second viewmodel should be able to refresh itself without having to be on the GUI thread.
A quick, but unlikely to work thing to try is ( I say unlikely because i havent been able to get any performance benefits from it )
using (Dispatcher.CurrentDispatcher.DisableProcessing())
{
//notification code here
}
And of course, if your second viewModel is grabbing data from somewhere, make sure it is async.
Upvotes: 1