捕获silverlight滚轮事件

2018-01-16 14:26:28 浏览数 (1)

silverlight小技巧

捕获silverlight滚轮事件

  1. 在页面初始化时添加代码
    • HtmlPage.Window.AttachEvent("DOMMouseScroll", OnMouseWheel);
    • HtmlPage.Window.AttachEvent("onmousewheel", OnMouseWheel);
    • HtmlPage.Document.AttachEvent("onmousewheel", OnMouseWheel);
  2. Mozilla/Safari浏览器监听detail属性,IE/Opera浏览器监听wheelDelta属性

private void OnMouseWheel(object sender, HtmlEventArgs args) {     double mouseDelta = 0;     ScriptObject e = args.EventObject;     // Mozilla and Safari        if (e.GetProperty("detail") != null)     {         mouseDelta = ((double)e.GetProperty("detail"));     } // IE and Opera        else if (e.GetProperty("wheelDelta") != null)     {         mouseDelta = ((double)e.GetProperty("wheelDelta"));     }     mouseDelta = Math.Sign(mouseDelta); }

0 人点赞