我已经实现了这篇文章中的代码:http ://wblo.gs/YvF 。一切都按预期工作,但我不知道如何在事件触发时访问传递给事件处理程序的参数。我知道有命令参数,但我如何使用它来访问 EventArgs?这是我实现的代码...
拖动输入类
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
public class DragEnter : Attachment<Control, DragEnterBehavior, DragEnter>
{
private static readonly DependencyProperty behaviorProperty = Behavior();
public static readonly DependencyProperty CommandProperty = Command(behaviorProperty);
public static readonly DependencyProperty CommandParameterProperty = Parameter(behaviorProperty);
public static void SetCommand(Control control, ICommand command) { control.SetValue(CommandProperty, command); }
public static ICommand GetCommand(Control control) { return control.GetValue(CommandProperty) as ICommand; }
public static void SetCommandParameter(Control control, object parameter) { control.SetValue(CommandParameterProperty, parameter); }
public static object GetCommandParameter(Control buttonBase) { return buttonBase.GetValue(CommandParameterProperty); }
}
DragEnterBehavior 类
using System.Windows.Controls;
using Microsoft.Practices.Prism.Commands;
public class DragEnterBehavior : CommandBehaviorBase<Control>
{
public DragEnterBehavior(Control selectableObject)
: base(selectableObject)
{
selectableObject.DragEnter += (sender, args) => ExecuteCommand();
}
}
实施代码
public ICommand EditItemCommand
{
get
{
if (editItemCommand == null)
editItemCommand = new RelayCommand(param => EditItemControl(), pre => IsItemEditButtonEnabled());
return editItemCommand;
}
}
public void EditItemControl()
{
...
ChangedView(itemEditorViewModel);
}
<ListBox Behaviors:DragEnter.Command="{Binding EditItemCommand}" ...
对此的任何帮助将不胜感激。谢谢你!