2017-02-01 22 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