Reputation: 1422
I have my first MVVM Light app and I have been very good and put nothing in the code behind. For performance reasons, the chart control I am using though needs a call to turn off it's updating and then turn it on again after the chart series have been updated. So I need to call a method on the control from the ViewModel.
Now I can make all of this happen through a "bigger hammer" approach by handing a reference to the chart control into the ViewModel through the locator's MainStatic method. I find myself thinking this is really not the way this is supposed to be done and I'm trying to do everything in the "MVVM way". Can any MVVM Light guru's show me the way? All I've found poking around is people sending Commands from the code behind into the ViewModel... I need to go the other way... or at least I think I do... ;-)
Upvotes: 3
Views: 441
Reputation: 93601
The "updating" switch should have been exposed via a bindable property rather than need function calls. Then you simply turn it on and off via a binding to a property of the View Model.
As that is apparently not the case, perhaps you should wrap the chart control in your own user control or sub-class it (slightly harder). Then you can expose any properties you want (including an "Updating" property, whose setter calls the update methods).
I personally have no qualms in using non-MVVM methods (i.e. code-behind) on basic user controls, as they should be treated more like third-party controls than part of your app. Wrapping, or sub-classing, existing controls just leads to a better library of reusable components.
Upvotes: 2