Click here to Skip to main content
15,879,096 members
Articles / Desktop Programming / WPF

WPF Themes and Skins Engine

Rate me:
Please Sign up or sign in to vote.
4.80/5 (27 votes)
22 Jan 2008CPOL6 min read 296.2K   16.5K   168  
In this article, I will talk about different techniques to load WPF themes and skins. I will also provide a helper class for loading and unloading themes.
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"	
	
	x:Name="mainWindow" x:Class="Tomers.WPF.Themes.MainWindow"	
	
	ResizeMode="NoResize"
	WindowStartupLocation="CenterScreen"
	SizeToContent="WidthAndHeight"
    Title="Skin Selector"
	Height="300"
	Width="300" Background="{DynamicResource BorderBrush}" Foreground="#FFF2F2F2">
	
	<Window.Resources>
		<LinearGradientBrush x:Key="BorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
			<GradientStop Color="#FF474747" Offset="0"/>
			<GradientStop Color="#FF000000" Offset="1"/>
			<GradientStop Color="#FF2A2A2A" Offset="0.593"/>
		</LinearGradientBrush>
	</Window.Resources>
	
	<DockPanel LastChildFill="True">
			
		<Border BorderThickness="2" CornerRadius="5" Padding="4" Margin="4">
			<Border.BorderBrush>
				<LinearGradientBrush EndPoint="0.5,0.056" StartPoint="0.5,0.944">
					<GradientStop Color="#FF666666" Offset="0"/>
					<GradientStop Color="#FF747474" Offset="1"/>
				</LinearGradientBrush>
			</Border.BorderBrush>
			<ListBox BorderThickness="0"
				ItemsSource="{Binding}"
				SelectedValue="{Binding Path=CurrentSkin, ElementName=mainWindow, Mode=TwoWay}" Foreground="#FFFFFFFF" >
				<ListBox.Background>
					<LinearGradientBrush EndPoint="0.5,0.496" StartPoint="1.25,0.99">
						<GradientStop Color="#FF000000" Offset="0"/>
						<GradientStop Color="#FF6A6A6A" Offset="1"/>
						<GradientStop Color="#FF262626" Offset="0.181"/>
					</LinearGradientBrush>
				</ListBox.Background>
			</ListBox>
		</Border>

		<Border BorderThickness="2" CornerRadius="5" Padding="4" Margin="4">
			<StackPanel Margin="32,16,32,16">
				<Button Content="Button" Width="240" Height="30" Margin="0,4,0,4" />
				<CheckBox Content="Checkbox" Width="240" Height="30" Margin="0,4,0,4" Foreground="#FFFFFFFF" />
				<RadioButton Content="RadioButton" Width="240" Height="30" Margin="0,4,0,4" Foreground="#FFFFFFFF" />
				<ComboBox SelectedIndex="0" Width="240" Height="30" Margin="0,4,0,4" >
					<ComboBoxItem Content="Item 1" />
					<ComboBoxItem Content="Item 2" />
					<ComboBoxItem Content="Item 3" />
				</ComboBox>
				<ListBox IsSynchronizedWithCurrentItem="True" Width="240" Height="44" Margin="0,4,0,4">
					<ListBoxItem Content="ListBoxItem"/>
					<ListBoxItem Content="ListBoxItem"/>
					<ListBoxItem Content="ListBoxItem"/>
				</ListBox>
				<ProgressBar Value="50" Minimum="0" Maximum="100" Width="240" Height="30" Margin="0,4,0,4" />
			</StackPanel>
		</Border>
			
	</DockPanel>
	
</Window>


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
Architect CodeValue
Israel Israel
Tomer Shamam is a Software Architect and a UI Expert at CodeValue, the home of software experts, based in Israel (http://codevalue.net). Tomer is a speaker in Microsoft conferences and user groups, and in-house courses. Tomer has years of experience in software development, he holds a B.A degree in computer science, and his writings appear regularly in the Israeli MSDN Pulse, and other popular developer web sites such as CodePlex and The Code Project. About his thoughts and ideas you can read in his blog (http://blogs.microsoft.co.il/blogs/tomershamam).

Comments and Discussions