4

私たちは、バック オフィス製品用のかなり複雑な Silverlight 3 RIA UI に取り組んでいます。これの機能の一部は、ユーザーがテーマを選択できることです。Telerik テーマを使用しているため、App_Init 時にテーマの選択を適用する必要があります。

そのため、テーマの選択 UI を使用することはできますが、テーマを適用するにはアプリケーションを再起動する必要があります。

明らかに、ブラウザーでは、これは簡単です。HtmlPage にドロップして、JavaScript を挿入するだけです。

しかし、Out of browser アプリケーションについてはどうでしょうか? このためのもう 1 つの要件は、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 のモック ボタンによって開始された) 2 回目に ChangeTheme() メソッドが既知の作業テーマで呼び出されると、例外が発生します。

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 プロパティ、String s) ……など……

テーマを切り替えるのではなく、アプリケーションを再起動するというルートをたどりました。しかし、私たちは Silverlight を初めて使用するので、教育を受けることができてうれしく思います。:)

どちらのアプローチも素晴らしいでしょう。

4

2 に答える 2

3

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.

于 2010-02-12T12:07:10.010 に答える
0

最初に設定した場合、2 番目のテーマは機能しますか?

残念ながら、スタック トレースを確認するだけでは何が問題なのかを正確に判断することはできません。新しいサポート チケットを開くか、telerik.com のフォーラム投稿を開くことをお勧めします。そうすれば、動作するサンプルをお送りできます。XAML にバグが含まれている可能性もありますので、テーマを送っていただけると大変助かります。

于 2010-02-13T10:12:32.180 に答える