2011-08-23 3 views
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); 
      } 
     } 
    } 
} 

답변

2

Interactivity 기능은 다음과 같이 사용할 수 없습니다, 정상 Triggers, EventTriggers 또는 스타일 자체에 속하지 않습니다. 이 같은 요소에 사용할 수 있습니다 :

<Button> 
    <i:Interaction.Triggers> 
     <!-- ... --> 
    </i:Interaction.Triggers> 
</Button> 

오류는 포괄 EventTriggerRoutedEvent을 설정하지 않음으로써 발생하지만, 당신이 그것을 설정 않은 경우에도 새로운 오류가 따를 것입니다.

+0

오케이 .. 사용자 정의 컨트롤을 만들지 않고도 KeyDown 이벤트에 수정 로직을 추가하는 방법에 대한 다른 제안이 있습니까? – maridob