70c68bef23
Got the stuff for the ApplicationCommands.Open from https://codingcontext.wordpress.com/2008/12/10/commandbindings-in-mvvm/.
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using GalaSoft.MvvmLight;
|
|
using System.Windows.Input;
|
|
using System;
|
|
using System.Windows;
|
|
using GalaSoft.MvvmLight.CommandWpf;
|
|
|
|
namespace xunit.runner.wpf.ViewModel
|
|
{
|
|
public class MainViewModel : ViewModelBase
|
|
{
|
|
public MainViewModel()
|
|
{
|
|
////if (IsInDesignMode)
|
|
////{
|
|
//// // Code runs in Blend --> create design time data.
|
|
////}
|
|
////else
|
|
////{
|
|
//// // Code runs "for real"
|
|
////}
|
|
|
|
}
|
|
|
|
public ICommand ExitCommand { get; } = new RelayCommand(OnExecuteExit);
|
|
|
|
public CommandBindingCollection CommandBindings { get; }
|
|
= CreateCommandBindings();
|
|
|
|
private static CommandBindingCollection CreateCommandBindings()
|
|
{
|
|
var openBinding = new CommandBinding(ApplicationCommands.Open, OnExecuteOpen);
|
|
CommandManager.RegisterClassCommandBinding(typeof(MainViewModel), openBinding);
|
|
|
|
return new CommandBindingCollection
|
|
{
|
|
openBinding,
|
|
};
|
|
}
|
|
|
|
private static void OnExecuteOpen(object sender, ExecutedRoutedEventArgs e)
|
|
{
|
|
MessageBox.Show("Open clicked");
|
|
}
|
|
|
|
private static void OnExecuteExit()
|
|
{
|
|
Application.Current.Shutdown();
|
|
}
|
|
}
|
|
} |