title: MVVM Command in Datatemplate
body: <p>I have in my XAML a Datatemplate like this:</p>
  
  <pre><code>&lt;DataTemplate x:Key="SheetToTemplate"&gt;
              &lt;TextBox Name="_txtToSheet"
                      Text="{Binding Path=SHEET_TO, UpdateSourceTrigger=PropertyChanged}" 
                     HorizontalAlignment="Stretch" 
                     HorizontalContentAlignment="Center"
                     VerticalAlignment="Center"
                     Style="{StaticResource DigitOnlyTextBoxStyle}" &gt;
                  &lt;i:Interaction.Triggers&gt;
                      &lt;i:EventTrigger EventName="TextChanged"&gt;
                          &lt;i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=DataContext.FilterTextChangedCommand }" &gt;
                          &lt;/i:InvokeCommandAction&gt;
                      &lt;/i:EventTrigger&gt;
                  &lt;/i:Interaction.Triggers&gt;
              &lt;/TextBox&gt;
          &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>This is my viewmodel with essential part:</p>
  
  <pre><code>RelayCommand _filterTextChangedCommand;
  public ICommand FilterTextChangedCommand
  {
      get
      {
          if (_filterTextChangedCommand == null)
          {
              _filterTextChangedCommand = new RelayCommand(
                  param =&gt; TextChange(param),
                  param =&gt; true);
          }
  
          return _filterTextChangedCommand;
      }
  }
  
  private object TextChange(object param)
  {
      throw new NotImplementedException();
  }
  </code></pre>
  
  <p>This is the error I get in output:</p>
  
  <blockquote>
    <p>System.Windows.Data Error: 4 : Cannot find source for binding with
    reference 'RelativeSource FindAncestor,
    AncestorType='System.Windows.Controls.UserControl',
    AncestorLevel='1''.
    BindingExpression:Path=DataContext.FilterTextChangedCommand;
    DataItem=null; target element is 'InvokeCommandAction'
    (HashCode=46858895); target property is 'Command' (type 'ICommand')</p>
  </blockquote>
  
  <p>I don't understand why the event isn't fired.
  Any suggestion?</p>
  
  <p>ps. Note that the property of the textbox is correctly bound.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>here the full control</p>
  
  <pre><code>&lt;ListView Grid.Row="0"
                      ItemsSource="{Binding Path=SelectedOperations}"
                      Margin="5,10,5,5" 
                      Name="WorkOrders" 
                      SelectionMode="Single"
                      FontSize="13"
                      Background="AliceBlue"
                      BorderBrush="AliceBlue"&gt;
  
      &lt;!--Style of items--&gt;
      &lt;ListView.ItemContainerStyle&gt;
          &lt;Style TargetType="{x:Type ListViewItem}"&gt;
              &lt;!--Properties--&gt;
              &lt;Setter Property="Control.HorizontalContentAlignment" Value="Stretch" /&gt;
              &lt;Setter Property="Control.VerticalContentAlignment" Value="Center" /&gt;
              &lt;!--Trigger--&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property="IsSelected" Value="True"&gt;
                      &lt;Setter Property="Background" Value="{x:Null}" /&gt;
                      &lt;Setter Property="BorderBrush" Value="{x:Null}" /&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/ListView.ItemContainerStyle&gt;
  
      &lt;ListView.View&gt;
          &lt;GridView &gt;
              &lt;GridViewColumn Header="Operation" CellTemplate="{StaticResource DetailIdenTemplate}"  Width="300"/&gt;
              &lt;GridViewColumn Header="From" CellTemplate="{StaticResource SheetFromTemplate}"  Width="50"/&gt;
              &lt;GridViewColumn Header="To" CellTemplate="{StaticResource SheetToTemplate}" Width="50" /&gt;
          &lt;/GridView&gt;
      &lt;/ListView.View&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>And here the ViewModel class definition:</p>
  
  <pre><code>public class OperativeSheetSelectionViewModel : ViewModelBase
  {
       //
  }
  </code></pre>