You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

3 years ago
using Microsoft.Xaml.Behaviors;
using System.Windows;
using System.Windows.Input;
namespace ECMonitor.MVVM
{
public class ExtendEventCommand : TriggerAction<DependencyObject>
{
/// <summary>
/// 事件要绑定的命令
/// </summary>
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));
/// <summary>
/// 绑定命令的参数,保持为空就是事件的参数
/// </summary>
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);
}
}
}