.NET     Console.WriteLine( "All Things .NET" );
.NET Nerd Blog Home
5.30.2007

 
WPF Custom Control - generic.xaml
I was writing a custom control today - started by using the VS 2005 "Add New Item..." dialog. After providing the filename, it barfed with a message "Value does not fall within the expected range". Obviously the new item wizard doesn't like something about my project. It actually created the code-behind file successfully, but nothing else, so I was left to setup the themes\generic.xaml file myself. Easy enough, right?

Created a simple folder in the project, called it "themes", then created a simple generic.xaml file, which contained a ResourceDictionary. Now when using the custom control from some window, I would get nothing. argh. Looked at the compile settings for generic.xaml, Build Action "Page", "Do not copy" ... looks good. Struggled around for a bit, then finally compared to another VS 2005 project started from scratch, where the add new item works.

The answer: AssemblyInfo.cs needs a ThemeInfo attribute.
Mine looks like this (sans comments), and it all seems to work now...

[assembly: ThemeInfo(
ResourceDictionaryLocation.None,
ResourceDictionaryLocation.SourceAssembly )]


Comments:
I had a similar problem. When trying to separate an XBAP into two projects, one that contains only the page1 and another project containing all the rest which was a "class library" project. (This was done to use one codebase both for the XBAP and a standalone). Then the ThemeInfo that you wrote about was not created in the new project, so i had to add that on my own. Thanks for the info :-)
 
Post a Comment

Powered by Blogger