Bind command to `DataTemplate` in `ContextMenu` when using multiple templates?
<p>I'm trying to give a context menu items with different look and functionality, but I cannot find a way to bind commands to these items. Each menu item's view model is derived from one class <code>AbstractEntryViewModel</code>. Here is a shortened example of my current project's structure. Using <code>ContextMenu.Resources</code> is the only way I found to bind a template to a certain type.</p>

<pre class="lang-xml prettyprint-override"><code>&lt;ContextMenu ItemsSource="{Binding Entries}"&gt;
    &lt;ContextMenu.Resources&gt;

        &lt;DataTemplate DataType="{x:Type local:NopEntryViewModel}"&gt;
            &lt;!-- Content --&gt;
        &lt;/DataTemplate&gt;

        &lt;HierarchicalDataTemplate
            DataType="{x:Type local:GroupEntryViewModel}"
            ItemsSource="{Binding Entries}"&gt;
            &lt;!-- Content --&gt;
        &lt;/HierarchicalDataTemplate&gt;

        &lt;!-- More templates --&gt;

    &lt;/ContextMenu.Resources&gt;
&lt;/ContextMenu&gt;
</code></pre>

<pre class="lang-cs prettyprint-override"><code>internal abstract AbstractEntryViewModel : INotifyPropertyChanged {
    public abstract void Invoke ();
    // ...
}

internal NopEntryViewModel : AbstractEntryViewModel {
    public override void Invoke () {}
}

internal GroupEntryViewModel : AbstractEntryViewModel {
    public override void Invoke () { /* ... */ }
    // ...
}

// More view models
</code></pre>

<p>Normally I can bind a command to a <code>MenuItem</code> like so</p>

<pre><code>&lt;MenuItem Command="{Binding StaticResourceOrViewModelProperty}" /&gt;
</code></pre>

<p><strong>How can I do the same thing with data templates? Is there an invisible container, a wrapper for the data template's content, that I can use to bind a command to?</strong></p>