Click here to Skip to main content
15,886,199 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.4K   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.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Diagnostics;

namespace Tomers.WPF.Themes.Skins
{
	public sealed class LooseXamlSkin : Skin
	{
		public LooseXamlSkin(string name, Uri source) : base (name)
		{
			this._sources = new List<Uri>();
			this._sources.Add(source);
		}

		public LooseXamlSkin(string name, IList<Uri> sources) : base (name)
		{
			this._sources = new List<Uri>(sources);
		}

		protected override void LoadResources()
		{
			foreach (Uri uri in _sources)
			{
				ResourceDictionary skinDictionary = new ResourceDictionary();
				try
				{
					skinDictionary.Source = uri;
				}
				catch (Exception ex)
				{
					Debug.WriteLine("Change error: " + ex.ToString());
					throw;
				}
				Resources.Add(skinDictionary);
			}
		}

		private readonly List<Uri> _sources;
	}
}

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