这个问题是关于如何使用上下文菜单,它是在主窗口中作为用户控件创建的。用户控制就像..
<UserControl x:Class="contextmenu1.context"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" >
<UserControl.Resources>
<ContextMenu x:Key="conmen" >
<MenuItem Header="Cut" Foreground="Black" FontSize="14" >
<!--<MenuItem.Icon >
<Image Source="Images/cut.png" Height="20" Width="20" />
</MenuItem.Icon>-->
</MenuItem>
<Separator />
<MenuItem Header="Copy" Foreground="Black" FontSize="14">
<!--<MenuItem.Icon>
<Image Source="Images/copy.png" />
</MenuItem.Icon>-->
</MenuItem>
<Separator />
<MenuItem Header="Paste" Foreground="Black" FontSize="14">
<!--<MenuItem.Icon>
<Image Source="Images/paste.png" />
</MenuItem.Icon>-->
</MenuItem>
<Separator />
<MenuItem Header="Delete" Foreground="Black" FontSize="14">
</MenuItem>
<Separator />
</ContextMenu>
<!--<Style TargetType="Button">
<Setter Property="ContextMenu" Value="{StaticResource conmen}"/>
</Style>-->
</UserControl.Resources>
</UserControl>
主窗口代码就像..
<Window x:Class="contextmenu1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dc="clr-namespace:contextmenu1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button x:Name="conbut" Content="RightClick" HorizontalAlignment="Left" Margin="234,135,0,0"/>
<dc:context />
</Grid>
</Window>
我包含了所需的命名空间,但不知何故,当我单击按钮时,上下文菜单没有出现,感谢您的帮助。