Siverlight 获取浏览器信息(高度、宽度、滚动条位置.....)

    /// <summary> 浏览器屏幕信息类  
    /// </summary> 
    public class Browser
    {
        /// <summary>     
        /// During static instantiation, only the Netscape flag is checked     
        /// </summary>     
        static Browser()
        {
            _isNavigator = HtmlPage.BrowserInformation.Name.Contains("Netscape");
        }

        /// <summary>     
        /// Flag indicating Navigator/Firefox/Safari or Internet Explorer     
        /// </summary>     
        private static readonly bool _isNavigator;

        /// <summary>     
        /// Provides quick access to the window.screen ScriptObject     
        /// </summary>     
        private static ScriptObject Screen
        {
            get
            {
                var screen = (ScriptObject)HtmlPage.Window.GetProperty("screen");

                if (screen == null)
                {
                    throw new InvalidOperationException();
                }

                return screen;
            }
        }

        /// <summary>     
        /// Gets the window object's client width     
        /// </summary>     
        public static double ClientWidth
        {
            get
            {
                return _isNavigator ? (double)HtmlPage.Window.GetProperty("innerWidth")
                    : (double)HtmlPage.Document.Body.GetProperty("clientWidth");
            }

        }

        /// <summary>     
        /// Gets the window object's client height     
        /// </summary>     
        public static double ClientHeight
        {
            get
            {
                return _isNavigator ? (double)HtmlPage.Window.GetProperty("innerHeight")
                    : (double)HtmlPage.Document.Body.GetProperty("clientHeight");
            }
        }

        /// <summary>     
        /// Gets the current horizontal scrolling offset     
        /// </summary>     
        public static double ScrollLeft
        {
            get
            {
                return _isNavigator ? (double)HtmlPage.Window.GetProperty("pageXOffset")
                    : (double)HtmlPage.Document.Body.GetProperty("scrollLeft");
            }
        }

        /// <summary>     
        /// Gets the current vertical scrolling offset     
        /// </summary>     
        public static double ScrollTop
        {
            get
            {
                return _isNavigator ? (double)HtmlPage.Window.GetProperty("pageYOffset")
                    : (double)HtmlPage.Document.Body.GetProperty("scrollHeight");
            }
        }

        /// <summary>     
        /// Gets the width of the entire display     
        /// </summary>     
        public static double ScreenWidth
        {
            get
            {
                return (double)Screen.GetProperty("width");
            }
        }

        /// <summary>     
        /// Gets the height of the entire display     
        /// </summary>     
        public static double ScreenHeight
        {
            get
            {
                return (double)Screen.GetProperty("height");
            }
        }

        /// <summary>     
        /// Gets the width of the available screen real estate, excluding the dock     
        /// or task bar     
        /// </summary>     
        public static double AvailableScreenWidth
        {
            get
            {
                return (double)Screen.GetProperty("availWidth");
            }
        }

        /// <summary>     
        /// Gets the height of the available screen real estate, excluding the dock     
        /// or task bar     
        /// </summary>     
        public static double AvailableScreenHeight
        {
            get
            {
                return (double)Screen.GetProperty("availHeight");
            }
        }

        /// <summary>     
        /// Gets the absolute left pixel position of the window in display coordinates     
        /// </summary>     
        public static double ScreenPositionLeft
        {
            get
            {
                return _isNavigator ? (double)HtmlPage.Window.GetProperty("screenX")
                    : (double)HtmlPage.Window.GetProperty("screenLeft");
            }
        }

        /// <summary>     
        /// Gets the absolute top pixel position of the window in display coordinates     
        /// </summary>     
        public static double ScreenPositionTop
        {
            get
            {
                return _isNavigator ? (double)HtmlPage.Window.GetProperty("screenY")
                    : (double)HtmlPage.Window.GetProperty("screenTop");
            }
        }  
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值