2017-04-06 104 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

相關問題