你好,
所以这将是我的第一个问题,因为我没有找到任何可以回答我的问题的东西。
初始情况
我SolidColorBrush
在我的<Window.Resources>
<SolidColorBrush x:Key="BackgroundBrush" Color="{DynamicResource BackgroundColor}"/>
<Color x:Key="BackgroundColor">PeachPuff</Color>
然后我把我的绑定Border
到SolidColorBrush
<Border Background="{DynamicResource ResourceKey=BackgroundBrush}" />
在应用程序启动时,我读取了一个保存背景颜色的 xml 文件。
// Some XML Loading stuff -> backgroundColor is a Color
this.Resources["BackgroundColor"] = backgroundColor;
这就像一个魅力。我可以更改 xml 文件中的颜色,边框的背景是我在 xml 文件中定义的任何颜色。
实际问题
现在我将SolidColorBrush
和的定义移到了Color
我的App.xaml文件中,并将颜色更改为:
Application.Current.Resources["BackgroundColor"] = backgroundColor;
但是现在边界的背景不再改变了。它只是边框的默认颜色。无论我在我的 xml 文件中写什么。
当我调试里面的内容时
Application.Current.Resources["BackgroundColor"]
分配的颜色
Application.Current.Resources["BackgroundColor"] = backgroundColor;
实际上是在
Application.Current.Resources["BackgroundColor"]
但背景没有改变......
背景
我有两个窗户。一个主窗口和一个首选项窗口。在首选项窗口中,我希望能够更改主窗口的 FontFamily/Type/Weight/Color 等。
我的第一种方法是在主窗口资源中定义所有样式并将我想要更改的值传递给首选项窗口并读出更改然后更新主窗口资源中的资源。
由于这非常有效,我现在想将样式移动到 app.xaml 并在那里读取和更新它们,这样我就不必将它们传递到首选项窗口并再次从那里读取它们。