I’m having an issue with calling a method on a UserControl. Hear me out:
-
I have a UserControl
someControlin SomeView.xaml -
SomeView.xaml’s DataContext is SomeViewModel.cs
-
I want to be able to call
someControl.DoStuff()somehow, somewhere. -
DoStuff is not UI specific (I could have just called DoStuff from the code-behind of SomeView.Xaml.Cs if it was UI specific, but in this case, it may not be.)
Any ideas?
Thanks!
You’re probably not going to like the answer, but your ViewModel should have no knowledge of your UI. If you have a non-UI method on your UserControl, it’s probably in the wrong place.
The only thing I could think of is that you may want to implement some type of messaging (like they have in MVVM Light) that could trigger the execution.
It’s either that, or rethink how you’ve architected your code.