wpf: binding a command defined in a datatemplate
===

I know there are few answers on this topic. But none of them was working in my case.

I have a ListView with a style and a ItemContainerStyle. In the ItemContainer Style I define some triggers in order to use a different DataTemplate depending if the item in the list is selected or not. Then, finally in the datatemplate I have a context menu with a command. The problem is how to bind the command to the viewmodel.

This is the ListView:

        <ListView
            x:Name="lstPersons"
            Grid.Row="1"
            Style="{StaticResource ListViewStyle}"
            ItemContainerStyle="{StaticResource ItemContainerStyle}"
            DataContext="{Binding}"
            ItemsSource="{Binding Path=Persons}"
            Tag="{Binding}"
            SelectedItem="{Binding Path=SelectedPerson, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        </ListView>


and these are the styles, datatemplates and contextmenu (defined in a resource dictionary). 
The commands in the context menu do not work....:

        <ContextMenu x:Key="SelectedItemContextMenu">
            <MenuItem
                Header="Do Something"
                Command="{Binding Path=DataContext.DoSomethingCmd, ElementName=LayoutRoot}">
            </MenuItem>
            <MenuItem
                Header="Do Something"
                Command="{Binding PlacementTarget.Tag.DoSomethingCmd, RelativeSource={RelativeSource AncestorType=ContextMenu}}">
            </MenuItem>
        </ContextMenu>

    <DataTemplate
        x:Key="ItemTemplate">
        <Canvas
            Margin="4"
            Width="60"
            Height="60"
            Background="LightGray">
            <TextBlock
                Foreground="Black"
                Margin="2 0 0 0"
                Opacity="0.5"
                FontFamily="Segoe UI"
                Text="{Binding Path=FirstName}" />
        </Canvas>
    </DataTemplate>

    <DataTemplate
        x:Key="ItemSelectedTemplate">
        <Grid>
            <Border
                BorderBrush="Black"
                BorderThickness="1"
                Margin="3"
                ContextMenu="{DynamicResource SelectedItemContextMenu}">
                <Canvas
                    Width="60"
                    Height="60"
                    Background="LightBlue">
                    <TextBlock
                        Foreground="Black"
                        Margin="2 0 0 0"
                        Opacity="0.5"
                        FontFamily="Segoe UI"
                        Text="{Binding Path=FirstName}" />
                </Canvas>
            </Border>
        </Grid>
    </DataTemplate>

    
    <!--style of the listviewitem-->
    <Style
        TargetType="{x:Type ListViewItem}"
        x:Key="ItemContainerStyle">
        <Setter
            Property="ContentTemplate"
            Value="{StaticResource ItemTemplate}" />
        <Style.Triggers>
            <Trigger
                Property="IsSelected"
                Value="True">
                <Setter
                    Property="ContentTemplate"
                    Value="{StaticResource ItemSelectedTemplate}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    
    <!--style of the listview-->
    <Style
        TargetType="{x:Type ListBox}"
        x:Key="ListViewStyle">
        <Setter
            Property="Template">
            <Setter.Value>
                <ControlTemplate
                    TargetType="{x:Type ListBox}">
                    <Grid>
                        <Border>
                            <ScrollViewer
                                Focusable="false">
                                <WrapPanel
                                    IsItemsHost="True"
                                    Orientation="Horizontal"
                                    Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"/>
                            </ScrollViewer>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>




