我正在尝试在我的样式中添加一个事件触发器,但由于某种原因它不起作用。它给我一个错误 {"Value cannot be null.\r\nParameter name: routedEvent"} 我的目标是在其 KeyDown 事件中添加我的控件的修复逻辑,有人知道发生了什么吗?
下面的样式在我的 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);
}
}
}
}