WPF Behavior InvokeCommandAction Command CommandParameter

FredGrit發表於2024-07-07
//xaml
<behavior:Interaction.Triggers>
    <behavior:EventTrigger EventName="MouseWheel" SourceObject="{Binding ElementName=img}">
        <behavior:InvokeCommandAction Command="{Binding MouseWheelCmd}"  
                                      PassEventArgsToCommand="True"
                                      CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=MouseButton}}" >                        
        </behavior:InvokeCommandAction>
    </behavior:EventTrigger>
</behavior:Interaction.Triggers>


//cs
  private void InitCmds()
  {
      MouseWheelCmd =new DelCmd(MouseWheelCmdExecuted,MouseWheelCmdCanExecuted);
  }

  private bool MouseWheelCmdCanExecuted(object obj)
  {
      return true;
  }

  private void MouseWheelCmdExecuted(object obj)
  { 
      var mouseWheelEventArgs=obj as MouseWheelEventArgs;
      if(mouseWheelEventArgs != null) 
      {
         //TO DO
      }
  }

相關文章