Silverlight 3 退出浏览器 - 重新启动“应用程序”

发布于 2024-08-21 11:17:03 字数 1728 浏览 8 评论 0原文

我们正在为我们的后台产品开发一个相当复杂的 Silverlight 3 RIA UI。其部分功能是用户可以选择主题。我们使用 Telerik 主题,这要求我们在 App_Init 时应用主题选择。

因此,我们当然可以有一个主题选择 UI,但随后我们需要重新启动应用程序才能应用主题。

显然,在浏览器中,这很容易 - 我们只需放到 HtmlPage 并注入一些 JavaScript 即可。

但是浏览器外应用程序又如何呢?对此的另一个要求是一旦 OOB 检测到并下载了应用程序的更新版本。

(已经搜索过这一点,似乎没有人解决这一点)

更新 1(感谢 Valeri)

我们已经应用了 Valeri 的代码,但遇到了问题。我们认为主题可能只能设置一次。我们有:

  • 将 XAML 移出到新的 UserControl (LayoutMockup)
  • 将 RootVisual 设置为网格并将 MainPage 添加到 App_Init 中的网格 在

我们的 MainPage 上,我们有(Class1 是我们想象中的标题主题):

public MainPage()
    {
        InitializeComponent();
        this.InitializeUI();
        Class1 customTheme = new Class1();
        customTheme.Source = new Uri("/Migturbo_Spring;Component/Themes/MyGeneric.xaml", UriKind.Relative);
        ChangeTheme(customTheme);


    }

以及进一步的代码:

    public void ChangeTheme(Theme theme)
    {
        StyleManager.ApplicationTheme = theme; // FAILS HERE 2ND TIME
        this.LayoutRoot.Children.Clear();
        this.InitializeUI();
    } 


    private void InitializeUI()
    {
        this.LayoutRoot.Children.Add(new LayoutMockup());
    } 

第一次运行时,它有效。正确应用了“Spring/Class1”主题。 第二次(由 UI 上的模拟按钮启动)使用已知的工作主题调用 ChangeTheme() 方法时,我们得到一个异常:

System.Exception 未被用户处理 代码 Message="错误 HRESULT E_FAIL 已从 COM 调用返回 组件。” StackTrace: 在 MS.Internal.XcpImports.CheckHResult(UInt32 小时) 在 MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj,DependencyProperty 属性, 字符串) ……等等……

我们选择了重新启动应用程序而不是切换主题,因为我们在某处读到这是不可能的。但我们是 Silverlight 的新手,很高兴接受教育。 :)

任何一种方法都很棒。

We're working on a fairly complex Silverlight 3 RIA UI for our back office product. Part of the functionality of this is that the user may select themes. We're using Telerik themes and these require us to apply the theme selection at the time of App_Init.

So we can certainly have a selection UI for the themes, but then we need to restart the application to apply the themes.

Obviously, in a browser, this would be easy - we just drop to HtmlPage and inject some JavaScript.

But what about an Out of browser application? Another requirement for this is once the OOB has detected and downloaded an updated version of the application.

(Have searched around for this and no-one seems to address this point)

UPDATE 1 (Thanks Valeri)

We've applied Valeri's code but are getting problems. We think that the theme may only be settable the once. We have:

  • Moved the XAML out into a new UserControl (LayoutMockup)
  • Set the RootVisual to a Grid and added the MainPage to the Grid in App_Init

On our MainPage, we have (Class1 is our imaginitively titled theme):

public MainPage()
    {
        InitializeComponent();
        this.InitializeUI();
        Class1 customTheme = new Class1();
        customTheme.Source = new Uri("/Migturbo_Spring;Component/Themes/MyGeneric.xaml", UriKind.Relative);
        ChangeTheme(customTheme);


    }

and also the further code:

    public void ChangeTheme(Theme theme)
    {
        StyleManager.ApplicationTheme = theme; // FAILS HERE 2ND TIME
        this.LayoutRoot.Children.Clear();
        this.InitializeUI();
    } 


    private void InitializeUI()
    {
        this.LayoutRoot.Children.Add(new LayoutMockup());
    } 

The first time this runs, it works. The "Spring/Class1" theme is correctly applied.
The second time (initiated by a mock button on the UI) the ChangeTheme() method is called with a known working theme, we get an exception:

System.Exception was unhandled by user
code Message="Error HRESULT E_FAIL
has been returned from a call to a COM
component.
" StackTrace:
at MS.Internal.XcpImports.CheckHResult(UInt32
hr)
at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper
obj, DependencyProperty property,
String s)
...... etc ......

We went the route of restarting the application as opposed to switching themes because we had read somewhere that it wasn't possible. But we are new to Silverlight and are happy to be educated. :)

Either approach would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书间行客 2024-08-28 11:17:03

您可以将应用程序 UI 添加到单独的 UserControl 中,而不是将其添加到 RootVisual 控件(通常是 MainPage.xaml)中,该控件将在 MainPage 的代码隐藏中实例化。当您更改主题时,您只需创建此 UserControl 的一个新实例并替换旧实例。例如:

public class MainPage : UserControl
{
    public MainPage()
    {
        this.InitializeComponent();
        this.InitializeUI();
    }

    public void ChangeTheme(Theme theme)
    {
        StyleManager.ApplicationTheme = theme;
        this.LayoutRoot.Children.Clear();
        this.InitializeUI();
    }

    private void InitializeUI()
    {
        this.LayoutRoot.Children.Add(new UIRoot());
    }
}

其中 UIRoot 是包含应用程序代码的 UserControl,MainPage 仅包含 Grid,其中 x:Name=LayoutRoot。当需要更改主题时,您只需调用 ChangeTheme 方法。

我希望这有帮助。

Instead of adding your application UI in the RootVisual control (usually MainPage.xaml) you could add it in a separate UserControl, that will be instantiated inside the MainPage’s code-behind. When you change the theme, you will just need to create a new instance of this UserControl and replace the old one. For example:

public class MainPage : UserControl
{
    public MainPage()
    {
        this.InitializeComponent();
        this.InitializeUI();
    }

    public void ChangeTheme(Theme theme)
    {
        StyleManager.ApplicationTheme = theme;
        this.LayoutRoot.Children.Clear();
        this.InitializeUI();
    }

    private void InitializeUI()
    {
        this.LayoutRoot.Children.Add(new UIRoot());
    }
}

Where UIRoot is the UserControl that contains the application code and MainPage contains only a Grid, with x:Name=LayoutRoot. When the theme has to be changed you only need to call the ChangeTheme method.

I hope this helps.

琉璃梦幻 2024-08-28 11:17:03

如果您最初设置第二个主题,它是否有效?

不幸的是,我无法仅通过查看堆栈跟踪来说出确切的问题是什么,您知道,SL 堆栈跟踪有时不提供有用的信息。我建议您在 telerik.com 上开立新的支持票证或论坛帖子,以便我可以向您发送工作示例。您的 XAML 也可能包含错误,因此如果您将您的主题发送给我们,将会有很大帮助。

Does the second theme work if you set it initially?

Unfortunately I cannot say what's the exact problem only by looking at the stack trace, you know, the SL stack traces sometimes do not provide helpful info. I would suggest opening a new support ticket or a forum post on telerik.com so I could send you a working sample. It is also possible that your XAML contains bugs, so it would be of great help if you send us your themes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文