Themes/generic.xaml

Recently I have been anatomizing Kevin’s Bag-O-Tricks. I was quite freaked out when I was trying to figure out how those custom controls are able to find their “Skins”. It turns out that Themes/generic.xaml plays the non-trivial role. Well, I don’t think I should go on with my shameful experience to discover this. Let me just focus on its function.

Here I quote the words from The FlexWinds Blog:

” The standard controls that are available out of the box are useful for most scenarios. However you do want the ability to create your own custom controls. WPF provides you that ability and also gives you a chance to define a default style for your control. Since your custom control will be in a separate .Net assembly, the default style is specified in a generic.xaml file that sits in the /themes folder. When WPF loads your control, it probes into the /themes/generic.xaml file and looks for a style definition for that control (TargetType = your control’s type). ”

Another thing needed to bear in mind is:

AssemblyInfo.cs needs a ThemeInfo attribute, with the value of
[assembly: ThemeInfo(ResourceDictionaryLocation.SourceAssembly, ResourceDictionaryLocation.SourceAssembly)]

P.S.

Here is a good tutorial teaching you how to create and apply custom themes.

~ by Martin on September 27, 2007.

3 Responses to “Themes/generic.xaml”

  1. Hi i tried to run that custom theme example.. but i got IO exception
    Cannot find resource in the line themeList.Add((ResourceDictionary)Application.LoadComponent(new Uri(@”RD.CustomThemes;;;component\themes/customthemes.luna.baml”, UriKind.Relative))); in ApplicationStartup method.. Please tell me the solution.
    By
    anandakumar
    aranandakumar@gmail.com

  2. At http://www.xamltemplates.net you can see themes and there is one for free you can download and use. It has all the controls stylized.

  3. Thank you so much, this saved a lot of slamming my head against a wall. :)

    thank you

Leave a Reply