When trying to pass the control in xaml
, we write the following code:
<MenuItem x:Name="NewMenuItem" Command="{Binding MenuItemCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}}" />
I'm trying to create a MenuItem
programmatically, like this:
var pluginMenuItem = new MenuItem
{
Header = "NewMenuItem,
Command = MenuItemCommand,
CommandParameter = "{Binding RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType={x:Type MenuItem}}}"
};
This passes the string
"{Binding RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType={x:Type MenuItem}}}"
as the CommandParameter
.
What am I missing?