捕获silverlight滚轮事件

 


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);
}


posted @ 2008-09-01 10:12  王喆(nasa)  阅读(822)  评论(0编辑  收藏  举报