using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Example
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
CommandBinding cbinding = new CommandBinding(MainWindow.GetButtonContentCmd);
cbinding.Executed += Cbinding_Executed;
cbinding.CanExecute += Cbinding_CanExecute;
this.CommandBindings.Add(cbinding);
this.textCommand.OnCanExecute = (obj) => true;
this.textCommand.OnExecute += TextCommand_OnExecute;
this.butCustom.Command = this.textCommand;
}
private void TextCommand_OnExecute(object? obj)
{
MessageBox.Show("自这义命令被调用!");
}
private void Cbinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void Cbinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show(e.Source.ToString());
}
public static RoutedCommand GetButtonContentCmd = new RoutedCommand();
public CustomCommand textCommand = new CustomCommand();
public class CustomCommand : ICommand
{
public string? Command { get; set; }
public CustomCommand() { }
public CustomCommand(string command, Action