Reusing elements in StandardStyles.xaml

In one of my previous blogs (second point), I mentioned not to modify the StandardStyles.xaml, but instead to create your own resource dictionary. I also mentioned how to declare your custom styles dictionary in the App.xaml file.

If you want to reference or build upon from an existing style in the StandardStyles.xaml file, do the following:

1. Remove the entry for StandardStyles.xaml in the App.xaml file

2. Add your custom resource dictionary in the App.xaml file

   1:  <!-- App.xaml -->
   2:  <Application.Resources>
   3:    <ResourceDictionary>
   4:      <ResourceDictionary.MergedDictionaries>
   5:        <ResourceDictionary Source="Common/CustomStyles.xaml"/>
   6:      </ResourceDictionary.MergedDictionaries>
   7:    </ResourceDictionary>
   8:  </Application.Resources>
3. List the StandardStyles.xaml as a merged dictionary in your custom resource file.
 
   1:  <!-- Common/CustomStyles.xaml -->
   2:  <ResourceDictionary>
   3:    <ResourceDictionary.MergedDictionaries>
   4:      <ResourceDictionary Source="StandardStyles.xaml"/>
   5:    </ResourceDictionary.MergedDictionaries>
   6:   
   7:    <!-- TitleTextStyle is declared in StandardStyles.xaml -->
   8:    <Style x:Key="MaxMoveCountStyle" TargetType="TextBlock" BasedOn="{StaticResource TitleTextStyle}">
   9:      <Setter Property="FontSize" Value="15"/>
  10:    </Style>
  11:  </ResourceDictionary>

No Comments