0
내 스타일에 eventtrigger를 추가하려고하지만 어떤 이유로 작동하지 않습니다. 내게 "null 값일 수 없습니다. \ r \ n 파라미터 이름 : routedEvent"} 내 목표는 내 제어의 수정 로직을 KeyDown 이벤트에 추가하는 것입니다. 아무도 무슨 일이 일어나고 있는지 전혀 알지 못합니까?Xaml의 EventTrigger
아래 스타일은 내 Theme.xaml 안에 있습니다.
<Style.Triggers>
<EventTrigger>
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<Behaviors:ExecuteCommandAction Command="{Binding TabKeyDownCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</EventTrigger>
</Style.Triggers>
가 여기 내 ExecuteCommandAction 클래스입니다 :
/// <summary>
/// Behaviour helps to bind any RoutedEvent of UIElement to Command.
/// </summary>
[DefaultTrigger(typeof (UIElement), typeof (EventTrigger), "KeyDown")]
public class ExecuteCommandAction : TargetedTriggerAction<UIElement>
{
/// <summary>
/// Dependency property represents the Command of the behaviour.
/// </summary>
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.RegisterAttached("CommandParameter",
typeof (object),
typeof (ExecuteCommandAction),
new FrameworkPropertyMetadata(null));
/// <summary>
/// Dependency property represents the Command parameter of the behaviour.
/// </summary>
public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached("Command",
typeof (ICommand
),
typeof (
ExecuteCommandAction
),
new FrameworkPropertyMetadata
(null));
/// <summary>
/// Gets or sets the Commmand.
/// </summary>
public ICommand Command
{
get { return (ICommand) GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
/// <summary>
/// Gets or sets the CommandParameter.
/// </summary>
public object CommandParameter
{
get { return GetValue(CommandParameterProperty); }
set { SetValue(CommandParameterProperty, value); }
}
/// <summary>
/// Invokes the action.
/// </summary>
/// <param name="parameter">The parameter to the action. If the action does not require a parameter, the parameter may be set to a null reference.</param>
protected override void Invoke(object parameter)
{
if (Command != null)
{
if (Command.CanExecute(CommandParameter))
{
Command.Execute(CommandParameter);
}
}
}
}
오케이 .. 사용자 정의 컨트롤을 만들지 않고도 KeyDown 이벤트에 수정 로직을 추가하는 방법에 대한 다른 제안이 있습니까? – maridob