小编sum*_*man的帖子

禁用右键单击并使用MVVM在WPF中启用左键单击上下文菜单

码:

<Button Style="{StaticResource HPForegroundStyle}" IsTabStop="False"                 
        Command="{Binding ForegroundPhoneCommand}"  Click="Button_Click">
                    <Button.ContextMenu>                   
                        <ContextMenu ItemsSource="{Binding OptionsMenuItemList}"                            ItemContainerStyle="{StaticResource ContextMenuItemStyle}" 
                                     IsOpen="{Binding IsMenuOpen}"                                        
                                     PlacementTarget="{Binding RelativeSourc={RelativeSource AncestorType={x:Type Button}}}">
                        </ContextMenu>
                    </Button.ContextMenu>
    </Button>
Run Code Online (Sandbox Code Playgroud)

我正在使用MVVM模式.在ViewModel中,我有一个属性'IsMenuOpen',它控制上下文菜单打开关闭.问题是我能够禁用右键单击而不能在左键单击时显示上下文菜单.

wpf contextmenu

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

contextmenu ×1

wpf ×1