Click here to Skip to main content
15,892,005 members
Articles / Programming Languages / C#

Silverlight Dynamic Themes

Rate me:
Please Sign up or sign in to vote.
4.92/5 (11 votes)
6 Jan 2012CPOL6 min read 56.6K   5.9K   29  
This article describes how to dynamically apply themes to a Silverlight application.
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Brushes.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <FontFamily x:Key="SystemFontFamily">Segoe UI, Lucida Sans Unicode, Verdana</FontFamily>
    <FontFamily x:Key="DocumentFontFamily">Calibri</FontFamily>

    <!-- Font Sizes. -->
    <sys:Double x:Key="ContentFontSize">13</sys:Double>
    <sys:Double x:Key="DefaultFontSize">12.5</sys:Double>
    <sys:Double x:Key="InputFontSize">11</sys:Double>
    <sys:Double x:Key="NormalFontSize">11</sys:Double>
    <sys:Double x:Key="Heading1FontSize">36</sys:Double>
    <sys:Double x:Key="Heading2FontSize">24</sys:Double>
    <sys:Double x:Key="Heading3FontSize">21</sys:Double>
    <sys:Double x:Key="Heading4FontSize">18</sys:Double>
    <sys:Double x:Key="Heading5FontSize">15</sys:Double>
    <sys:Double x:Key="Heading6FontSize">11</sys:Double>

    <!--TitleBarStyle-->
    <Style x:Key="TitleBarStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="Text" Value=""/>
    </Style>

    <!--MainInstructionStyle-->
    <Style x:Key="MainInstructionStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource MainInstructionBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="17"/>
    </Style>

    <!--SecondaryInstructionStyle-->
    <Style x:Key="SecondaryInstructionStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="13"/>
    </Style>

    <!--NormalTextStyle-->
    <Style x:Key="NormalTextStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="13"/>
    </Style>

    <!--EmphasizedTextStyle-->
    <Style x:Key="EmphasizedTextStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="FontWeight" Value="Bold"/>
    </Style>

    <!--EditableTextStyle-->
    <Style x:Key="EditableTextStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="13"/>
    </Style>

    <!--DisabledTextStyle-->
    <Style x:Key="DisabledTextStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource DisabledTextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="13"/>
    </Style>

    <!--LinkTextStyle-->
    <Style x:Key="LinkTextStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource LinkTextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="13"/>
    </Style>

    <!--LinkHoverStyle-->
    <Style x:Key="LinkHoverStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource LinkHoverBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="13"/>
    </Style>

    <!--GroupHeaderStyle-->
    <Style x:Key="GroupHeaderStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource MainInstructionBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="16"/>
    </Style>

    <!--FileNameStyle-->
    <Style x:Key="FileNameStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource SystemFontFamily}"/>
        <Setter Property="FontSize" Value="16"/>
    </Style>

    <!--DocumentTextStyle-->
    <Style x:Key="DocumentTextStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource DocumentFontFamily}"/>
        <Setter Property="FontSize" Value="14"/>
    </Style>

    <!--DocumentHeadingsStyle-->
    <Style x:Key="DocumentHeadingsStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource TextBrush}"/>
        <Setter Property="FontFamily" Value="{StaticResource DocumentFontFamily}"/>
        <Setter Property="FontSize" Value="21"/>
        <Setter Property="FontWeight" Value="SemiBold"/>
    </Style>
</ResourceDictionary>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Romania Romania
I have been a software developer for a while and still find this an interesting job.

Comments and Discussions