-
Notifications
You must be signed in to change notification settings - Fork 11
How to add a style
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:
-
Create a style file in the Styles folder. For this example, create DefaultStyle.xaml.
-
Make the root object StyleResourceDictionary.
-
Set the Name attribute. Notces the name is the same as the filename without the extension.
-
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>