title: "No target found for method" thrown by Caliburn Message.Attach()
body: <p>I have a list box for which I am styling ItemContainer to include a context menu. Here is the xaml for the same.</p>
  
  <pre><code>&lt;ListBox.ItemContainerStyle&gt;
      &lt;Style TargetType="{x:Type ListBoxItem}"&gt;
      ...
          &lt;Setter Property="ContextMenu"&gt;
              &lt;Setter.Value&gt;
                  &lt;ContextMenu&gt;
                      &lt;MenuItem Header="Remove Group" cal:Message.Attach="DeleteGroup"/&gt;
                  &lt;/ContextMenu&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <p>I have coded the target method in ViewModel as given below.</p>
  
  <pre><code>public void DeleteGroup() { //ToDo
      ...
  }
  </code></pre>
  
  <p>The ViewModel is set as the DataContext of the UserControl in which there is the ListBox.</p>
  
  <p>The above code results in <strong>"no target found for method"</strong>. I am not sure why this doesn't work. I have also tried the following variation</p>
  
  <pre><code>&lt;MenuItem Header="Remove Group" cal:Message.Attach="DeleteGroup"
            cal:Action.Target="{Binding ElementName=UCRelayDispositionView, Path=DataContext}"&gt;
  </code></pre>
  
  <p>where UCRelayDispositionView is the name of the UserControl.</p>
  
  <p>Why does the above code do not work?</p>
  
  <p><strong>Edit: 1</strong>
  Also tried the following</p>
  
  <pre><code>&lt;MenuItem Header="Remove Group" cal:Message.Attach="DeleteGroup"
            cal:Action.TargetWithoutContext="{Binding ElementName=UCRelayDispositionView, Path=DataContext}"&gt;
  </code></pre>
  
  <p>and this</p>
  
  <pre><code>&lt;MenuItem Header="Remove Group" cal:Message.Attach="DeleteGroup"
            cal:Action.TargetWithoutContext="{Binding ElementName=UCRelayDispositionView}"&gt;
  </code></pre>
  
  <p><strong>EDIT: 2</strong>
  I have tried to use the Tag in the following way on ItemContainer but it doesn't work either.</p>
  
  <pre><code>&lt;ListBox.ItemContainerStyle&gt;
      &lt;Style TargetType="{x:Type ListBoxItem}"&gt;
          &lt;Setter Property="Tag" Value="{Binding Path=DataContext, ElementName=UCRelayDispositionView}"/&gt;
          &lt;Setter Property="ContextMenu"&gt;
              &lt;Setter.Value&gt;
                  &lt;ContextMenu&gt;
                      &lt;MenuItem Header="Remove Group" 
                                cal:Message.Attach="DeleteGroup()" 
                                cal:Action.TargetWithoutContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}"/&gt;                                    
                      &lt;/ContextMenu&gt;
              &lt;/Setter.Value&gt;
      &lt;/Style&gt;
  &lt;/ListBox.ItemContainerStyle&gt;
  </code></pre>
  
  <p><strong>EDIT 3: Binding Errors</strong></p>
  
  <pre><code>System.Windows.Data Error: 40 : BindingExpression path error: 'PlacementTarget' property not found on 'object' ''MenuItem' (Name='')'. BindingExpression:Path=PlacementTarget.Tag; DataItem='MenuItem' (Name=''); target element is 'MenuItem' (Name=''); target property is 'TargetWithoutContext' (type 'Object')
  System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=UCRelayDispositionView'. BindingExpression:Path=DataContext; DataItem=null; target element is 'ContextMenu' (Name=''); target property is 'Tag' (type 'Object')
  </code></pre>