1
이 기사의 코드는 http://wblo.gs/YvF입니다. 모든 것이 예상대로 작동하지만 이벤트가 발생할 때 이벤트 핸들러에 전달 된 인수에 액세스하는 방법을 알지 못합니다. 명령 매개 변수가 있다는 것을 알고 있지만 어떻게 EventArg에 액세스 할 수 있습니까? 다음은이에 어떤 도움을 주시면 감사하겠습니다명령 동작 첨부 파일 인수
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}" ...
내가 구현 한 코드 ...
의 dragEnter 클래스
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();
}
}
구현 코드입니다. 고맙습니다!