如何将上下文菜单添加到 wpf 数据网格?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3286583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:56:28  来源:igfitidea点击:

How to add context menu to wpf datagrid?

wpfdatagridwpf-controls

提问by StillWorking28269

Just wondering how to add a ContextMenu to a DataGrid? I want to be able to right click anywhere on the DataGrid. Can someone please provide a simple hello world example (just popup messagebox or something)?

只是想知道如何将 ContextMenu 添加到 DataGrid?我希望能够右键单击 DataGrid 上的任意位置。有人可以提供一个简单的 hello world 示例(只是弹出消息框或其他东西)?

Thanks!

谢谢!

回答by StillWorking28269

<DataGrid>
    <DataGrid.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Click Me" Click="MenuItem_Click" />
        </ContextMenu>
    </DataGrid.ContextMenu>
</DataGrid>