首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Silverlight判断目前模式是OOB还是Web

2012-11-17 
Silverlight判断当前模式是OOB还是WebSilverlight可以以Web方式和OOB模式运行,在OOB模式中有一些功能是不

Silverlight判断当前模式是OOB还是Web

Silverlight可以以Web方式和OOB模式运行,在OOB模式中有一些功能是不能使用的,我们可以在程序中加一些处理代码来对应不同的操作,这里我修改了App类的代码,加入一个模式判断的代码,原App代码如下:

public partial class App : Application    {        public App()        {            this.Startup += this.Application_Startup;            this.Exit += this.Application_Exit;            this.UnhandledException += this.Application_UnhandledException;                        InitializeComponent();        }


修改后的代码如下:

    public partial class App : Application    {        public static App self;        public bool IsOOB = false;        public App()        {            this.Startup += this.Application_Startup;            this.Exit += this.Application_Exit;            this.UnhandledException += this.Application_UnhandledException;                        InitializeComponent();            self = this;            try            {                var win = HtmlPage.Window;            }            catch            {                IsOOB = true;            }        }


使用代码如下:

            if (App.self.IsOOB)            {                //这是OOB模式            }            else            {                //这是Web模式            }

热点排行