• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ASP.NET系统开发-生Blog
博客园    首页    新随笔    联系   管理    订阅  订阅
Silverlight获取浏览器高度、宽度类
using System; 
    using System.Net; 
    using System.Windows; 
    using System.Windows.Controls; 
    using System.Windows.Documents; 
    using System.Windows.Ink; 
    using System.Windows.Input; 
    using System.Windows.Media; 
    using System.Windows.Media.Animation; 
    using System.Windows.Shapes; 
    using System.Windows.Browser; 
    namespace Lib 
    { 
        /// <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 bool _isNavigator; 
     
            /// <summary>    
            /// Provides quick access to the window.screen ScriptObject    
            /// </summary>    
            private static ScriptObject Screen 
            { 
                get 
                { 
                    ScriptObject 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"); 
                } 
            } 
     
        } 
    } 
posted on 2012-08-07 16:01  生  阅读(1846)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3