2017-02-01 52 views
1

我的代码重写一个CalendarDatePicker资源(CalendarDatePickerCalendarGlyphForeground)在XAML。与二传手覆盖控制资源的样式文件

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

现在,我需要重新使用此代码,在我的style文件的项目创建一个通用的风格,在别人CalendarDatePicker用在我的项目,像这样:

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

我应该怎么做与二传手?

如果我想一个通用的样式应用到所有项目的日历,而无需在每个日历样式=要输入的StaticResource {...},我应该怎么定义这个风格?

+0

真的只是采取'SolidColorBrush'资源,在资源字典中把它(保持X:键名称相同),因此它覆盖在继承顺序的缺省值。不需要风格模板的东西。 –

回答

4

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

因此,例如,用自己的颜色在每一个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造型的控制。

+0

雅这样的... +1 –

+0

我尝试没有“CalendarDatePicker.Resources”标记添加到我的样式文件“CalendarDatePicker.Resources”和内,以某种方式,在CalendarDatePickerCalendarGlyphForeground财产,而不是直接。新手们的东西...... Thx! – CarlosTI