我添加了MahApps
资源,例如 App.xaml:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
<!-- accent resource -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/blue.xaml" />
<!-- theme resource -->
<!-- change "BaseLight" to the theme you want -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/basedark.xaml" />
</ResourceDictionary.MergedDictionaries>
....
它适用于我的所有窗口,但我有一个特殊的窗口(WindowA
),我想要使用不同的颜色,所以我将MahApps
资源添加到此窗口
WindowA.xaml:
<controls:MetroWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
<!-- accent resource -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/blue.xaml" />
<!-- theme resource -->
<!-- change "BaseLight" to the theme you want -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/basedark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</controls:MetroWindow.Resources>
现在我想动态地应用我的强调色,所以我使用这样的代码:
ThemeManager.ChangeAppStyle(appOrWindow,
ThemeManager.GetAccent("Amber"),
ThemeManager.GetAppTheme("basedark"));
Amber
的标题栏颜色(WindowA
颜色)的结果很酷但是我有一个label
(Lable 1
) UserControl
内的TestUserControl
(WindowA
),其颜色为Blue
!
WindowA&gt; TestUserControl&gt; Lable 1
lable 1
中的TestUserControl
xaml标记:
<Label Foreground="{StaticResource AccentColorBrush}">Lable1</Label>
我希望将{StaticResource AccentColorBrush}
Foreground
颜色的所有元素颜色更改为Amber
UserControls
WindowA
内的所有元素AccentColorBrush
{ {1}}。
我认为StaticResource
正在UserControl
中使用MahApps
资源declared
。如何强制它在App.xaml
中使用MahApps
资源declared
。
我该如何解决这个问题?
EDIT1
如果我将WindowA.xaml
的重音应用于Red
,则Application
颜色将更改为label 1
颜色。
答案 0 :(得分:1)
将此添加到UserControl.Resources
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/amber.xaml" />
答案 1 :(得分:0)
您应该使用DynamicResource
代替StaticResource
作为前景。
<Label Foreground="{DynamicResource AccentColorBrush}">Lable1</Label>
希望有所帮助。