在 WPF 中创建通用上下文菜单

发布于 2024-09-26 13:32:37 字数 204 浏览 0 评论 0原文

在我的应用程序中,我有很多网格(Infragistics)。我想创建一个上下文菜单,它将实现许多常见功能,即:删除、保存布局等,并且如果特定网格需要的不仅仅是常见功能,还可以添加到该网格的菜单中。我想创建一个上下文菜单,而不必在整个项目中重复相同的代码。

我不知道如何实现这一点。可能的?示例 xaml 和/或代码将会有所帮助。

非常感谢,

瑞克

In my app I have many grids (Infragistics). I would like to create a context menu that will implement many of the common functions ie: delete, save layout, etc. and if a specific grid needs more than the common functions be able to add to the menu for that grid. I would like to create one context menu and not have to repeat the same code throughout project.

I have no idea on how to accomplish this. Possible? Example xaml and/or code will be helpful.

Thanks a bunch,

Rick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝礼 2024-10-03 13:32:37

我过去曾尝试做类似的事情(不是使用上下文菜单,而是使用列表视图)。虽然我从未让它 100% 正常工作,因为我无法正确绑定某些项目,但我相信前进的方向如下;

  • 创建上下文菜单“样式”,可能在单独的资源字典中。在这里,您将设计所有上下文菜单将包含的元素。

  • 当您需要更加自定义的上下文菜单时,请将上一步中定义的基本上下文菜单样式应用于您的元素,然后使用 BaseOn 属性 使用此特定元素中的自定义项目扩展此上下文菜单。

很抱歉没有包含示例 XAML,但我使用的是移动设备,因此根本无法很好地构建 XAML。

希望这在某种程度上有帮助

I have attempted to do similar things is the past (not with a context menu but with a listview). While I never got it 100% working, as I couldn't get certain items to bind properly, I believe the way forward would be as follows;

  • Create a Context Menu 'style', perhaps in a separate resource dictionary. Here you would design the elements that ALL context menu's will hold.

  • When you require a more customised context menu, apply the basic context menu style defined in the previous step to your element and then use the BasedOn attribute to extend this context menu with custom items within this specific element.

Apologies for not including example XAML but I am on a mobile device and therefore cannot contruct XAML very well at all.

Hope this helps to some degree

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文