I have been looking for this on Stack Overflow, but couldnt find an answer to this yet so I hope this isnt a duplicate...
I have an app using the MVVM pattern, I like to keep things clean, but sometimes a little code behind seems cleaner than the XAML workaround.
I want to know if it is possible to trigger a command from the codebehind.
I have set up a command reference in my view already (see below)
<local:CommandReference
x:Key="CommandReferencePreviewReportsCommand"
Command="{Binding PreviewReportsCommand}" />
What I want to do is be able to trigger the command reference or the ICommand from the c# code behind of the view. Does anyone know how to do this?
You can just invoke the command from the code-behind:
var parameter = null; // can also be any object you'd like to use as a parameter
this.PreviewReportsCommand.Execute(parameter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With