[英]WPF MahApps Change style of Window notworking for elements inside its UserControl
I added MahApps
resources like in App.xaml: 我在App.xaml中添加了
MahApps
资源:
<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>
....
It works well on all of my windows but i have a special window ( WindowA
) that i want be in a different color so i added the MahApps
resources to this window 它在我所有的窗口上都可以正常工作,但是我有一个特殊的窗口(
WindowA
),我希望将其设置为其他颜色,因此我将MahApps
资源添加到了该窗口
WindowA.xaml: 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>
Now i want apply my accent color dynamically to it, so i use some codes like this: 现在我想将其强调色动态地应用到它,所以我使用了一些像这样的代码:
ThemeManager.ChangeAppStyle(appOrWindow,
ThemeManager.GetAccent("Amber"),
ThemeManager.GetAppTheme("basedark"));
The result is cool for title bar color ( Amber
color) of the WindowA
BUT i have a label
( Lable 1
) in a UserControl
( TestUserControl
) inside WindowA
and its color is Blue
yet! 其结果是凉快标题栏颜色(
Amber
的颜色) WindowA
,但我有一个label
( Lable 1
)在UserControl
( TestUserControl
内) WindowA
和它的颜色是Blue
呢!
WindowA > TestUserControl > Lable 1
WindowA> TestUserControl>标签1
The lable 1
xaml tag inside TestUserControl
: TestUserControl
lable 1
xaml标签:
<Label Foreground="{StaticResource AccentColorBrush}">Lable1</Label>
I want change all element colors with {StaticResource AccentColorBrush}
Foreground
color to Amber
include all elements inside UserControls
of the WindowA
with AccentColorBrush
StaticResource
. 我想改变所有元素的颜色与
{StaticResource AccentColorBrush}
Foreground
颜色以Amber
包括里面的所有要素UserControls
的的WindowA
与AccentColorBrush
StaticResource
。
I think the UserControl
is using MahApps
resources declared
in App.xaml
. 我认为
UserControl
正在使用App.xaml
declared
MahApps
资源。 How can i force it to use MahApps
resources declared
in WindowA.xaml
. 我怎样才能迫使它使用
MahApps
资源declared
在WindowA.xaml
。
How can i fix this? 我怎样才能解决这个问题?
Edit1 编辑1
If i apply an accent like Red
to the Application
the label 1
color will be changed to the Red
color. 如果我向
Application
像Red
这样的强调,则label 1
颜色将更改为Red
。
将此添加到UserControl.Resources
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/amber.xaml" />
You should use DynamicResource
instead StaticResource
for the foreground. 您应该使用
DynamicResource
而不是StaticResource
作为前景。
<Label Foreground="{DynamicResource AccentColorBrush}">Lable1</Label>
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.