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模式
}