title: InvokeCommandAction CommandParameter always zero
body: <p>Background: I'm trying to enable and disable a command based on whether a textbox has text selected or not.</p>
  
  <p>According to my research I need to use event triggers. Either the InvokeCommandAction which this problem is about or the InvokeMethodAction which for some reason doesn't exist on my system.</p>
  
  <p>The Problem: I've set this program up as follows. It runs, the commands fire but the parameters are always zero.</p>
  
  <pre><code>&lt;Window x:Class="LogWpfApp.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
          xmlns:local="clr-namespace:LogWpfApp"
          mc:Ignorable="d"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Window.DataContext&gt;
          &lt;local:ViewModel /&gt;
      &lt;/Window.DataContext&gt;
      &lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="Auto" /&gt;
              &lt;ColumnDefinition Width="*" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto" /&gt;
              &lt;RowDefinition Height="*" /&gt;
              &lt;RowDefinition Height="Auto" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Button Grid.Row="0" Grid.Column="0" Content="Copy" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="75"
                  Command="{Binding CmdCopy}" CommandTarget="{Binding ElementName=textBoxNote}" CommandParameter="{Binding ElementName=textBoxNote}"/&gt;
          &lt;Button Grid.Row="0" Grid.Column="1" Content="Paste" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="75"
                  /&gt;
          &lt;TextBox x:Name="textBoxNote" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,0" TextWrapping="Wrap"
                   Text="{Binding Note}"&gt;
              &lt;i:Interaction.Triggers&gt;
                  &lt;i:EventTrigger EventName="SelectionChanged"&gt;
                      &lt;i:InvokeCommandAction Command="{Binding CmdSelectionLengthChanged}" CommandParameter="{Binding ElementName=textBoxNote, Path=SelectionLength}" /&gt;
                      &lt;i:InvokeCommandAction Command="{Binding CmdSelectionStartChanged}" CommandParameter="{Binding ElementName=textBoxNote, Path=SelectionStart}" /&gt;
                  &lt;/i:EventTrigger&gt;
              &lt;/i:Interaction.Triggers&gt;
          &lt;/TextBox&gt;
          &lt;Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Content="{Binding Clipboard}"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And here's the ViewModel:</p>
  
  <pre><code>public class ViewModel : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged;
  
      private RelayCommand&lt;TextBox, TextBox&gt; cmdCopy;
      private RelayCommand&lt;object, object&gt; cmdPaste = new RelayCommand&lt;object, object&gt;(foo =&gt; { }, (tb) =&gt; { return true; });
      private RelayCommand&lt;int, int&gt; cmdSelectionLengthChanged;
      private RelayCommand&lt;int, int&gt; cmdSelectionStartChanged;
      private String note = "This is some default initial text";
      private String clippboard = "";
      private int selectionLength = 0;
      private int selectionStart = 0;
  
  
  
      public ViewModel()
      {
          cmdCopy = new RelayCommand&lt;TextBox, TextBox&gt;(
              tb =&gt; { clippboard = tb.SelectedText; },
              tb =&gt; { return SelectionLength &gt; 0; /* tb != null &amp;&amp; tb.SelectionLength &gt; 0;*/ }
          );
  
          cmdSelectionLengthChanged = new RelayCommand&lt;int, int&gt;(
              length =&gt; {
                  Console.WriteLine("New SelectionLength {0}", length);
                  SelectionLength = length; cmdCopy.FireCanExecuteChanged(); },
              foo =&gt; { return true; }
          );
  
          cmdSelectionStartChanged = new RelayCommand&lt;int, int&gt;(
              start =&gt; {
                  Console.WriteLine("New SelectionStart {0}", start);
                  selectionStart = start; },
              foo =&gt; { return true; }
          );
      }
  
  
  
      public RelayCommand&lt;TextBox, TextBox&gt; CmdCopy =&gt; cmdCopy;
      public RelayCommand&lt;object, object&gt; CmdPaste =&gt; cmdPaste;
      public RelayCommand&lt;int, int&gt; CmdSelectionLengthChanged =&gt; cmdSelectionLengthChanged;
      public RelayCommand&lt;int, int&gt; CmdSelectionStartChanged =&gt; cmdSelectionStartChanged;
  
  
      public String Note
      {
          get { return note; }
          set
          {
              if (this.note != value)
              {
                  this.note = value;
                  PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Note)));
              }
          }
      }
  
      public String Clipboard
      {
          get { return clippboard; }
          private set
          {
              if (clippboard != value)
              {
                  clippboard = value;
                  PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Clipboard)));
              }
          }
      }
  
      public int SelectionLength
      {
          get { return selectionLength; }
          set
          {
              if (selectionLength != value)
              {
                  selectionLength = value;
                  PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectionLength)));
              }
          }
      }
  }
  </code></pre>