silverlight - 如何让 Silverlight 应用程序检查更新并要求用户升级?

标签 silverlight out-of-browser

我制作了一个浏览器外的silverlight应用程序,我希望每次有新的.xap文件自动更新已上传至服务器。

当用户右键单击应用程序并单击更新时,默认设置为“检查更新,但让我选择是否下载并安装它们 “:

alt text
(来源:deviantsart.com)

这让我相信,我的 Silverlight 应用程序可以自动检测服务器上是否存在新的 .xap 文件,如果存在,Silverlight 客户端会自动询问用户是否愿意安装。

  • 然而事实并非如此。我上传了一个新的 .xap 文件,但 Silverlight 应用程序不执行任何操作

  • 即使我将其添加到我的 App.xaml.cs 中:

--

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new BaseApp();
    if (Application.Current.IsRunningOutOfBrowser)
    {
        Application.Current.CheckAndDownloadUpdateAsync();
    }
}

并更新 .xap 文件,Silverlight 应用程序不执行任何操作

  • This information使我能够检查是否有更新,如果有,则告诉用户重新启动应用程序,但是当他重新启动应用程序时,什么也没有发生:

--

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new BaseApp();
    if (Application.Current.IsRunningOutOfBrowser)
    {
        Application.Current.CheckAndDownloadUpdateAsync();
        Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
    }
}

void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
    if (e.UpdateAvailable)
    {
        MessageBox.Show("An application update has been downloaded. " +
            "Restart the application to run the new version.");
    }
    else if (e.Error != null &&
        e.Error is PlatformNotSupportedException)
    {
        MessageBox.Show("An application update is available, " +
            "but it requires a new version of Silverlight. " +
            "Visit the application home page to upgrade.");
    }
    else
    {
        //no new version available
    }
}

如何让我的 Silverlight 应用程序在每次启动时检查是否有新的 .xap 文件,如果有,则将控制权传递给 Silverlight 客户端以询问用户是否要下载该文件,正如上面的对话所暗示的那样,这是可能的吗?

最佳答案

第一个对话框是关于如何安装 Silverlight 本身的更新,与您的应用程序无关。

使用 CheckAndDownloadUpdateAsync 应自动下载新的 XAP。根据文档,没有办法阻止您调用 CheckAndDownloadUpdateAsync 来安装新版本。

关于silverlight - 如何让 Silverlight 应用程序检查更新并要求用户升级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3032768/

相关文章:

c# - 在 XAML 中使用绑定(bind)设置样式

Silverlight:是否可以使用自定义鼠标光标/指针?

silverlight - 如何为我的 Silverlight 4 OOB 应用程序设置最小宽度和高度?

silverlight - 隔离存储、OOB 和删除应用程序

silverlight - 如何防止用户调整 silverlight 浏览器外窗口的大小?

.net - 在浏览器外访问 Silverlight 中的主机或 URL 信息

c# - 是否可以在 Windows Phone 7 文本框中放置 "hints"?

c# - 了解增加测试代码覆盖率的资源

c# - 使用 DispatchTimer 获得 1 毫秒精度的运行时间

silverlight - 如何在 Silverlight 4 浏览器外弹出窗口中将焦点设置在 TextBox 上