using Microsoft.Xaml.Behaviors; using System.Windows; using System.Windows.Input; namespace ECMonitor.MVVM { public class ExtendEventCommand : TriggerAction { /// /// 事件要绑定的命令 /// public ICommand Command { get { return (ICommand)GetValue(CommandProperty); } set { SetValue(CommandProperty, value); } } // Using a DependencyProperty as the backing store for MsgName. This enables animation, styling, binding, etc... public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(ExtendEventCommand), new PropertyMetadata(null)); /// /// 绑定命令的参数,保持为空就是事件的参数 /// public object CommandParateter { get { return (object)GetValue(CommandParateterProperty); } set { SetValue(CommandParateterProperty, value); } } // Using a DependencyProperty as the backing store for CommandParateter. This enables animation, styling, binding, etc... public static readonly DependencyProperty CommandParateterProperty = DependencyProperty.Register("CommandParateter", typeof(object), typeof(ExtendEventCommand), new PropertyMetadata(null)); //执行事件 protected override void Invoke(object parameter) { if (CommandParateter != null) parameter = CommandParateter; var cmd = Command; if (cmd != null) cmd.Execute(parameter); } } }