有没有办法预览合并到App.xaml资源中的DynamicResources?

问题描述 投票:0回答:0

我在 WPF 中有一个应用程序,并创建了一个服务,将我的画笔和颜色添加到 ResourceDictionary 中,然后将此字典与 App.xaml 资源合并。这看起来像这样(显然原始代码更大。这是主要思想):

private void ConfigureApplicationVisual()
{
    Resources.MergedDictionaries.Add(new AbdrakovBundledTheme()
    {
        IsDarkMode = true,
        ExtendedColors = new Dictionary<string, ColorPair>()
        {
            { "TextForeground", new ColorPair(Colors.AliceBlue, Colors.Black) },
            // similar things...
        }
    }.SetTheme());
}

(然后在 SetTheme 方法内部,颜色会像 sourceDictionary[name + "Color"] = value; 一样添加到 AbdrakovBundledTheme (继承自

ResourceDictionary
),并返回 AbdrakovBundledTheme 作为要进一步合并的字典)

那么我想要什么?我希望颜色出现在设计模式中(就像 StaticResource 那样)。我知道 WPF 在运行时编译并运行一些代码块以在设计器中显示它们。是否可以使用 DynamicResources 来做到这一点?
还有两件事:

  1. 我已经在 SO WPF 中的动态资源预览上看到了类似的问题,但我不能像他们那样做。我的 AbdrakovBundledTheme 也有点动态。
  2. 我尝试在 App 构造函数和 OnStartup 中调用该方法,但没有结果。
c# wpf resourcedictionary dynamicresource
© www.soinside.com 2019 - 2024. All rights reserved.