Click here to Skip to main content
15,896,111 members
Articles / Desktop Programming / WPF

Pluggable Styles and Resources in WPF with Language Converter Tool

Rate me:
Please Sign up or sign in to vote.
4.96/5 (17 votes)
31 Oct 2010CPOL9 min read 41.3K   749   31  
In this article, I have shown how you can build pluggable Resources for styles, Languages or any static objects, etc. Therefore building a new style doesn't hamper your code and you can easily plugin any new style to the application even though it is already in the production environment.
<ResourceDictionary x:Class="SilverRed.SilverResource"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit">
    
    <Color x:Key="ShadeHover">#AA220D</Color>
    <Color x:Key="ShadeBack">#AB2E0D</Color>
    <Color x:Key="ShadeHighlight">#AA330D</Color>
    <Color x:Key="ShadeBackground">#AAEEBB</Color>
    <Color x:Key="ShadeFadedBackground">#AACCDD</Color>
    
    <SolidColorBrush x:Key="ShadeHoverBrush"
                     Color="{StaticResource ShadeHover}"></SolidColorBrush>
    <SolidColorBrush x:Key="ShadeBackBrush"
                     Color="{StaticResource ShadeBack}"></SolidColorBrush>
    <SolidColorBrush x:Key="ShadeHighlightBrush"
                     Color="{StaticResource ShadeHighlight}"></SolidColorBrush>
    <SolidColorBrush x:Key="ShadeBackgroundBrush"
                     Color="{StaticResource ShadeBackground}"></SolidColorBrush>
    <SolidColorBrush x:Key="ShadeFadedBackgroundBrush"
                     Color="{StaticResource ShadeFadedBackground}"></SolidColorBrush>
    
    <LinearGradientBrush x:Key="HoverGradientBrush"
                         StartPoint="0,0"
                         EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="{StaticResource ShadeHover}"
                              Offset="0.0" />
                <GradientStop Color="{StaticResource ShadeFadedBackground}"
                              Offset="1.0" />
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>
    
    <Style TargetType="{x:Type ButtonBase}"
           x:Key="btnBasic">
        <Setter Property="Foreground"
                Value="{StaticResource ShadeHighlightBrush}" />
        <Setter Property="FontFamily"
                Value="Verdana" />
        <Setter Property="FontSize"
                Value="12" />
        <Setter Property="FontWeight"
                Value="Bold" />
        <Setter Property="MinWidth"
                Value="100"></Setter>
        <Setter Property="MinHeight"
                Value="45"></Setter>
        <Setter Property="Margin"
                Value="4"></Setter>
        <Setter Property="VerticalAlignment"
                Value="Center"></Setter>
        <Setter Property="Background">
            <Setter.Value>
                <RadialGradientBrush>
                    <GradientStop Color="{StaticResource ShadeFadedBackground}"
                                  Offset="0" />
                    <GradientStop Color="White"
                                  Offset="1" />
                </RadialGradientBrush>
            </Setter.Value>
        </Setter>

    </Style>
    <Style TargetType="{x:Type TextBlock}"
           x:Key="tbBasic">
        <Setter Property="FontFamily"
                Value="Calibri" />
        <Setter Property="FontSize"
                Value="18"></Setter>
        <Setter Property="ScrollViewer.CanContentScroll"
                Value="true" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="Foreground"
                Value="{StaticResource ShadeHighlightBrush}"></Setter>
    </Style>
    
    <Style TargetType="{x:Type Window}" x:Key="winBackgr">
        <Setter Property="Background" Value="{StaticResource ShadeFadedBackgroundBrush}" />
    </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
President
India India
Did you like his post?

Oh, lets go a bit further to know him better.
Visit his Website : www.abhisheksur.com to know more about Abhishek.

Abhishek also authored a book on .NET 4.5 Features and recommends you to read it, you will learn a lot from it.
http://bit.ly/EXPERTCookBook

Basically he is from India, who loves to explore the .NET world. He loves to code and in his leisure you always find him talking about technical stuffs.

Working as a VP product of APPSeCONNECT, an integration platform of future, he does all sort of innovation around the product.

Have any problem? Write to him in his Forum.

You can also mail him directly to abhi2434@yahoo.com

Want a Coder like him for your project?
Drop him a mail to contact@abhisheksur.com

Visit His Blog

Dotnet Tricks and Tips



Dont forget to vote or share your comments about his Writing

Comments and Discussions