<Style x:Key="tbNormal" TargetType="TextBlock">
<Setter Property="Margin" Value="0,0,10,0"/>
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="11"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
<Style x:Key="tbNormal" TargetType="TextBlock">
<Setter Property="Margin" Value="0,0,10,0"/>
<Setter Property="Foreground" Value="AliceBlue"></Setter>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="11"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
<Style x:Key="BasicStyle" TargetType="TextBlock">
<Setter Property="Margin" Value="0,0,10,0"/>
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="11"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
<Style x:Key="tbNormalBO" BasedOn="{StaticResource BasicStyle}" TargetType="TextBlock"/>
<Style x:Key="tbBoldBO" BasedOn="{StaticResource BasicStyle}" TargetType="TextBlock">
<Setter Property="FontWeight" Value="Bold" />
</Style>
<TextBlock Height="23" HorizontalAlignment="Left" Style="{StaticResource tbNormal}" Name="textBlock1" Text="KeyBased Normal style" />
<TextBlock Height="23" HorizontalAlignment="Left" Style="{StaticResource tbBoldBO}" Name="textBlock3" Text="KeyBased Based-On style"/>
<TextBlock Height="23" HorizontalAlignment="Left" Name="textBlock2" Text="Apply style to all textBlocks with no key define approach." />
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows"
xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TextBlock.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Finally, we need to load appropriate resources depending upon the selected theme. This can be done under Application StartUp event using below code:
if (this.CurrentSkin != null && this.CurrentSkin.ToLower().Equals("styleone"))
{
Uri uri = new Uri("/SLTheming;component/Themes/StyleOne/StyleOneSkin.xaml", UriKind.Relative);
ResourceDictionary dictionary = new ResourceDictionary();
dictionary.Source = uri;
Application.Current.Resources.MergedDictionaries.Add(dictionary);
}
else
{
Uri uri = new Uri("/SLTheming;component/Themes/Default/DefaultSkin.xaml", UriKind.Relative);
ResourceDictionary dictionary = new ResourceDictionary();
dictionary.Source = uri;
Application.Current.Resources.MergedDictionaries.Add(dictionary);
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)