2017-04-06 68 views
0

我对WPF完全陌生,我试图让一个现有的按钮显示菜单项的下拉菜单。如何将上下文菜单添加到按钮?

这是最好的方法是什么?

<Button Name="ModelReport" Template="{StaticResource GlassButton}" 
VerticalAlignment="Bottom" MouseEnter="ModelReport_MouseEnter" Click="CommandButton_Click"> 

    <StackPanel Background="Transparent" Orientation="Horizontal" Margin="5,4,5,4"> 
    <Image Width="16" Height="16" x:Name="ModelReportImage" Source="{StaticResource MyImgScrollInformation}" /> 
    <TextBlock VerticalAlignment="Center" Margin="3,0">Model Report</TextBlock> 
</StackPanel> 

</Button> 
+0

您尝试了哪些方法?您对这些方法有何看法?请分享。 – Versatile

回答

1

这是很容易的上下文菜单中的WPF添加到按钮:

<Button Content="1234"> 
    <Button.ContextMenu> 
     <ContextMenu> 
      <MenuItem Header="abcd" /> 
     </ContextMenu> 
    </Button.ContextMenu> 
</Button> 

然而,它的混乱和糟糕的UX!

除非用户精确知道在此特定按钮上有一个上下文菜单,否则它在用户界面中根本不可见。

更好的方法:

一个劈扣。

enter image description here

有一个免费版本或Extended WPF Toolkit Community Edition

相关问题