My Silverlight系列(11)—— Silverlight中的右键事件点击模拟(全局版本)
2009-04-25 12:04:33 来源:WEB开发网剩余的任务,就是向Javascript中AttachEvent:
1public sealed class RightClickHelper:IDisposable
2 {
3 public event EventHandler<MouseRightClickEventArgs> RightClick;
4 public RightClickHelper()
5 {
6 //if (!(Application.Current.Host.Settings.Windowless && HtmlPage.IsEnabled))
7 //throw new NotSupportedException("Must set the Windowless of the plug-in as true");
8 HtmlPage.Document.AttachEvent("oncontextmenu", this.OnContextMenu);
9 }
10
11 private void OnContextMenu(object sender, HtmlEventArgs e)
12 {
13 if (RightClick != null)
14 {
15 MouseRightClickEventArgs evtArgs = new MouseRightClickEventArgs(e.OffsetX, e.OffsetY);
16 RightClick(this, evtArgs);
17 if (evtArgs.Handled)
18 e.PreventDefault();
19 }
20 }
21
22 IDisposable Members#region IDisposable Members
23 public void Dispose()
24 {
25 HtmlPage.Document.DetachEvent("oncontextmenu", this.OnContextMenu);
26 }
27 #endregion
28 }
Tags:My Silverlight 系列
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接