Tag: 菜单元素名称

元素名称从ContextMenu中的MenuItem绑定

有没有人注意到ElementName绑定不能正确parsingContextMenu对象中包含的MenuItem对象? 看看这个例子: <Window x:Class="EmptyWPF.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" x:Name="window"> <Grid x:Name="grid" Background="Wheat"> <Grid.ContextMenu> <ContextMenu x:Name="menu"> <MenuItem x:Name="menuItem" Header="Window" Tag="{Binding ElementName=window}" Click="MenuItem_Click"/> <MenuItem Header="Grid" Tag="{Binding ElementName=grid}" Click="MenuItem_Click"/> <MenuItem Header="Menu" Tag="{Binding ElementName=menu}" Click="MenuItem_Click"/> <MenuItem Header="Menu Item" Tag="{Binding ElementName=menuItem}" Click="MenuItem_Click"/> </ContextMenu> </Grid.ContextMenu> <Button Content="Menu" HorizontalAlignment="Center" VerticalAlignment="Center" Click="MenuItem_Click" Tag="{Binding ElementName=menu}"/> <Menu HorizontalAlignment="Center" VerticalAlignment="Bottom"> <MenuItem x:Name="anotherMenuItem" Header="Window" Tag="{Binding ElementName=window}" […]