此随笔能令SL应用屏蔽默认的右键菜单,以及使用自己的右键菜单
首先,必须把aspx页面的<asp:Silverlight>标签的Windowless属性设置为true,这步很重要,切记!
接着,编写好自己的右键菜单控件,可以是Border或者其他
最后,就是使用ContextMenuInterceptor类来加载右键菜单,具体代码如下:
public partial class Page : UserControl
{
ContextMenuInterceptor _cmi = null;
public Page()
{
InitializeComponent();
_cmi = new ContextMenuInterceptor(MyField);
}
}
public class ContextMenuInterceptor
{
UIElment TextField;
public ContextMenuInterceptor(UIElement textField)
{
TextField = textField;
HtmlPage.Document.AttachEvent("oncontextmenu", this.OnContextMenu);
}
private void OnContextMenu(object sender, HtmlEventArgs e)
{
TextField.Text = "Right Clicked Blocked at "+e.OffsetX+","+e.OffsetY;
e.PreventDefault();
}
}