I would like to call a method of a ViewModel when a EventTrigger is raised in a View.
I want to do something like that, but in MVVM in my xaml code :
public partial class MyView : UserControl
{
public MyView()
{
InitializeComponent();
this.Loaded +=new System.Windows.RoutedEventHandler(ViewLoaded);
}
private void ViewLoaded(object sender, RoutedEventArgs e)
{
((MyViewModel)this.DataContext).BeginWork();
}
}
My apps is build with WPF 3.5, and I can not use Blend SKD.
Create a DependencyProperty of type
ICommand, call it “BeginWorkCommand” for example. Create a new class next to your viewmodel, or use a DelegateCommand to directly use it in your viewmodel. And finally bind this viewmodel command to your created dependency property.