I am completely confused using relativeSource and ancestorLevel. Relative source is used for to get source from another elements. But to do that successfully you have to count at what level is that element. (How to debug?) It is most confusing part in WPF.
In my example i have context menu that i want to bind datasource and then command. How would binding must be to get command in my vm? Thank you
 <Page.DataContext>
    <PDB:UsersViewModel x:Name="vm"/>
</Page.DataContext>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <!--Page Header info content-->
    <Grid Grid.Row="0">
        <TextBlock Text="{Binding SelectedUser.Name}"/>
        <TextBlock Text="{Binding ElementName=myGrd, Path=CurrentColumn.DisplayIndex}"/>
    </Grid>
    <!--Datagrid content-->
    <DataGrid x:Name="myGrd" 
              SelectionMode="Single"    
              SelectionUnit="Cell"
              CurrentItem="{Binding SelectedUser, Mode=TwoWay}"
              CurrentColumn="{Binding CurrentColumn, Mode=TwoWay}"
              IsReadOnly="True"
              Grid.Row="1" 
              ItemsSource="{Binding FilteredUserList}" 
              AutoGenerateColumns="True"             
              CanUserAddRows="False"
              >
        <DataGrid.Resources>
            <ContextMenu x:Key="ContextMenu">
                <ContextMenu.Items>
                    <MenuItem Header="{Binding 
                        RelativeSource={RelativeSource  
                        FindAncestor,
                        AncestorType={x:Type Page}, 
                        AncestorLevel=4}, Path=vm}" />
                </ContextMenu.Items>
            </ContextMenu>
        </DataGrid.Resources>
        <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
                <Setter Property="ContextMenu" Value="{StaticResource ContextMenu}"/>
            </Style>
        </DataGrid.CellStyle>
    </DataGrid>
</Grid>
 
    