0

アプリケーションのスタイルとコントロール テンプレートを定義したリソース ディクショナリがあります。ここで、画面解像度ごとに 1 つずつ、さまざまな画面解像度を対象とするリソース ディクショナリをさらに定義したいと考えています。クライアントの画面解像度を検出し、App.XAML で特定のリソース ディクショナリを読み込むにはどうすればよいですか?

私の現在の App.XAML:

<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources\BlueYellow\BlueYellowTheme.xaml" />
            </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
4

2 に答える 2

1

画面の解像度に基づいてリソースを切り替えることができることの価値を理解できます。明らかに、膨大な数の解像度を管理可能な短いリストにまとめて、現在の解像度に「最適」なものを見つけるために、いくつかの作業を行う必要があります。どうぞ。

App.cs

protected override void OnStartup(StartupEventArgs e)
{
  // Get the width and height, you might want to at least round these to a few values.
  var width = System.Windows.SystemParameters.PrimaryScreenWidth;
  var height = System.Windows.SystemParameters.PrimaryScreenHeight;

  // make the resource path from them.
  string resourceName = string.Format("Themes\resource{0}x{1}", width, height);

  // Add the resource to the app.
  Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)Application.LoadComponent(new Uri(resourceName, UriKind.Relative)));

  base.OnStartup(e);
}
于 2012-06-01T12:47:27.827 に答える
1

解像度に応じて適切なリソース ディクショナリ uri を返す markupExtension を作成し、次のように使用できると思います。

<ResourceDictionary Source="{ThemeUriAccordingToCurrentResolution}" />
于 2012-06-01T12:09:09.287 に答える