gpt4 book ai didi

wpf - WPF中的主要主题

转载 作者:行者123 更新时间:2023-12-03 15:02:50 29 4
gpt4 key购买 nike

我目前正在从事的wpf项目有一个小问题。我是WPF的新手。在我的app.xaml中,我正在为应用程序使用Microsoft Aero主题。我的app.xaml中有类似的内容

 <ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component/themes/Aero.NormalColor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

现在我想知道如何覆盖某些样式属性,例如对于Buttons,我想覆盖字体样式,同时保留其余的Aero样式。

如果我在窗口资源中为按钮定义样式,例如
 <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}" x:Key="RedTextBasedOnButton">
<Setter Property="Foreground" Value="Red" />
</Style>

并根据上述样式定义一个按钮

该按钮将释放所有航空样式属性。我认为问题在于我为样式定义 BasedOn 属性的方式
BasedOn="{StaticResource {x:Type Button}}"

我不认为资源是静态的,因为它来自dll,它可能应该是这样的。虽然不确定。
BasedOn="{DynamicResource {x:Type Button}}"

但是上面抛出异常,如果我的app.xaml中有多个resourcedictionary,该怎么办?露娜和经典。如何确定哪个默认用作默认设置,同时如何使用和覆盖另一个(例如luna)专门用于ui中某些控件的设置?因此,我的某些按钮将基于luna样式,而某些按钮将基于航空样式并进行一些进一步的修改?

任何想法?

问候,

最佳答案

对于您的特定问题

e.g. For Buttons I want to override the font style meanwhile retaining the rest of the aero style.



我会尝试在您的资源字典中添加以下内容:
<FontFamily x:Key="YourFont">Tahoma</FontFamily>

然后在您的样式中使用它:
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}" x:Key="RedTextBasedOnButton">
<Setter Property="FontFamily" Value="{StaticResource YourFont}"/>
</Style>

因此,您可以基于一个键来更改FontFamily。

我建议看这个 http://wpfthemes.codeplex.com/SourceControl/latest#WPF.Themes.Demo/Window1.xaml

关于wpf - WPF中的主要主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3565468/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com