2013-11-21 99 views
0

有沒有爲應用程序中的任何控件設置默認FontStyle的方法。 我爲Generic.xaml中的T​​extBlock設置了默認樣式,但是當我在應用程序中設置了textBlock的任何屬性時,它就開始使用主要的parrent風格,但不改變一些屬性。 有沒有辦法將我的風格設置爲所有TextBlocks的主風格?覆蓋所有控件的FontStyle

回答

2

是的。簡單地說,創建一個「匿名」樣式並將其加載到App.xaml中。你可能想看看here。在下面你可以找到我通常使用的方法。

Style.xaml

<ResourceDictionary ...> 
    <!-- a non anonymous style as base for all styles you may want to derive --> 
    <Style x:Key="TextBlockDefault" TargetType="TextBlock"> 
     <!-- every default property you want to set --> 
    </ Style> 

    <!-- now the anonymous style (no key attribute) --> 
    <Style BasedOn="{StaticResource TextBlockDefault}" TargetType="TextBlock" /> 
</ResourceDictionary> 

的App.xaml

<Application ...> 
    <Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="/<yourAppName>;component/<path>/Style.xaml" /> 
      </ ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application>