How can I tell my DataTemplate to bind to a property in the PARENT ViewModel?

The answer is this:

<DataTemplate x:Key="CodeGenerationMenuTemplate">
    <MenuItem 
        Header="{Binding Title}" 
        Command="{Binding DataContext.SwitchPageCommand,
    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Menu}}}" 
        CommandParameter="{Binding Title}"/>
</DataTemplate>

I just saw that Nir had given me the syntax to solve the above issue on this question: What is the best way in MVVM to build a menu that displays various pages?.

Leave a Comment