Reputation: 235
Following up on this question and its answer (which did solve my problem), I have a couple of questions:
ViewModelManager
to pass to the constructor of RequeryAllTheThings
? Currently, I am using the ViewModelBase.ViewModelManager
property in the first view model that loads, but this seems inelegant. I tried using the ServiceLocator
, but the object it returned never managed any view models.DataGrid
changes state. What is the correct approach?Upvotes: 1
Views: 51
Reputation: 5724
The IViewModelManager is registered in the ServiceLocator. Use the TypeFactory (which will resolve dependencies automatically from the ServiceLocator) to construct your types that require the IViewModelFactory.
The correct approach is to only invalidate the state of commands when it's necessary. The CommandManager.RequerySuggested invalidates nearly on any routed command (mouse moves, keyboards, etc). While this might work great on your Intel Core i7 super powered cpu, there are people in the world running slower machines. So Catel tries to find the best "out-of-the-box" experience possible, which is to invalidate the state if a property on the view model changes (which is normally the cause of a command state invalidation).
You could create your own watcher that listens to the relevant DG events also invalidate the commands in case of such an event.
Upvotes: 1