如何在Silverlight应用程序中删除默认的右键单击菜单 [英] How to remove default right click menu in silverlight applications

查看:108
本文介绍了如何在Silverlight应用程序中删除默认的右键单击菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

有什么方法可以删除Silverlight应用程序中的右键单击菜单.我在项目中遵循MVVM模式,而我的解决方案中包含几个Silverlight项目.我需要一个通用的解决方案来删除所有Silverlight项目中的右键菜单.谁能帮我. . .

Hi friends,

Is there any way to remove right click menu in Silverlight applications. I am following MVVM pattern in my project, and my solution contains several silverlight projects in it. I need a common solution to remove right click menu in all silverlight projects. Can any one help me. . .

推荐答案

在您的主页(或根视图)的后面代码中,只需挂接MouseRightButtonDown事件或重写OnMouseRightButtonDown函数即可.无论哪种情况,都将e.Handled属性设置为true以防止进一步处理.

In the code behind for your main page (or your root visual) simply hook the MouseRightButtonDown event or override the OnMouseRightButtonDown function. In either case, set the e.Handled property to true to prevent further processing.

protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
{
    e.Handled = true;
     // Best not to call the base method in this case because we don't want that behavior
     //base.OnMouseRightButtonDown(e);
}



如果需要,您还可以使用它来弹出自定义的右键单击菜单.在这种情况下,您可以将鼠标坐标用作上下文菜单对象的左上角.

您可以根据需要在较低级别上再次覆盖它.因此,例如,如果您具有树视图,并且希望显示自定义上下文菜单,则可以将该事件挂接到该容器(网格,面板,树视图等)上,然后弹出您的自定义菜单.鼠标事件从指针下方Z顺序的最高控件(层次结构中的最低事件)开始,并在层次结构树上冒泡"直到它们被处理或到达应用程序且未处理.

希望有帮助.



You can also use this to pop a custom right-click menu if you would like. In that case you use the mouse coordinates as the top-left corner of your context menu object.

You can override this again at a lower level if you wanted. So if you have a treeview, for example, that you wanted a custom context menu to appear, you could hook the event on that container (grid, panel, treeview, etc) and pop your custom menu. Mouse events start at the control highest in the Z-Order (which is the lowest in the hierarchy) under the pointer and bubble "up" the hierarchy tree until they are handled or they get to the app and go unhandled.

Hope that helps.


这篇关于如何在Silverlight应用程序中删除默认的右键单击菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆