Skip to content
Jared A Barneck edited this page May 21, 2015 · 1 revision

Styles can also be applied at run time. You can create any number of styles. Styles are not the same as Language styles.

  • Language Styles = Has styles changes specific to a language. For example, in Hebrew the FlowDirection changes to right to left.
  • Styles = The overall theme of the application. If you have a blue theme, the blue theme should remain in effect even if the language changes.

Style folder structure is simply. There is a single file for a style.

Styles\Default Style.xaml Styles\Red.xaml Styles\Blue.xaml

To add an additional style, follow these steps:

  1. Create a style file in the Styles folder. For this example, create DefaultStyle.xaml.

  2. Make the root object StyleResourceDictionary.

  3. Set the Name attribute. Notces the name is the same as the filename without the extension.

  4. Add some styles. This file could get massive as unlike the language file, this could hold all styles.

    <Globalization:StyleResourceDictionary 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:Globalization="clr-namespace:WPFSharp.Globalizer;assembly=WPFSharp.Globalizer" 
        Name="DefaultStyle"
        >
        <FlowDirection x:Key="FlowDirection_Default">LeftToRight</FlowDirection>
        <FlowDirection x:Key="FlowDirection_Reverse">RightToLeft</FlowDirection>
        <sys:Double x:Key="CommonFontSize">14</sys:Double>
    
        <Style TargetType="{x:Type Label}">
            <Setter Property="Foreground" Value="DarkOrange" />
            <Setter Property="Height" Value="Auto" />
            <Setter Property="Width" Value="Auto" />
            <Setter Property="FontSize" Value="{StaticResource ResourceKey=CommonFontSize}" />
            <Setter Property="Margin" Value="2" />
        </Style>
        <SolidColorBrush x:Key="MainWindowBackground" Color="White" />
    </Globalization:StyleResourceDictionary>
    
Clone this wiki locally