gpt4 book ai didi

c# - 在样式文件中使用 setter 覆盖控制资源

转载 作者:太空宇宙 更新时间:2023-11-03 21:04:43 24 4
gpt4 key购买 nike

我有代码在 XAML 中覆盖 CalendarDatePicker 资源 (CalendarDatePickerCalendarGlyphForeground)。

<CalendarDatePicker Style="{StaticResource CalendarDatePickerStyle}">
<CalendarDatePicker.Resources>
<SolidColorBrush x:Key="CalendarDatePickerCalendarGlyphForeground" Color="{StaticResource PrimaryColor}"/>
</CalendarDatePicker.Resources>
</CalendarDatePicker>

现在,我需要重用这段代码,在我的样式文件项目中创建一个通用样式,以便在我的项目中的其他 CalendarDatePicker 中使用,如下所示:

<Style x:Key="CalendarDatePickerStyle" TargetType="CalendarDatePicker">        
<Setter ....
</Style>

我应该如何使用 Setter 做到这一点?

如果我想将通用样式应用于所有项目日历而不必在每个日历样式中都键入 Style={StaticResource ...},我应该如何定义这种样式?

最佳答案

您可以直接将 SolidColorBrush 定义添加到您的 App.xaml 资源中,它将覆盖默认样式。最主要的是使用与控件使用相同的Key。

例如,要在每个 CalendarDatePicker 中用您自己的颜色覆盖 CalendarDatePickerCalendarGlyphForeground,请使 App.xaml 如下所示:

<Application
x:Class="App1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
RequestedTheme="Light">

<Application.Resources>
<SolidColorBrush x:Key="CalendarDatePickerCalendarGlyphForeground" Color="Green"/>
</Application.Resources>

在这里more info关于 UWP 中的样式控件。

关于c# - 在样式文件中使用 setter 覆盖控制资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41983402/

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