Reputation: 4667
I have a lookless control I've built that has a default style defined in generic.xaml in my Themes directory. I also have the following in the constructor.
static MyControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetadata(typeof(MyControl)));
}
public MyControl()
{
//DoSomeWork
}
Is there something else I'm suppose to set in WPF land? In Silverlight all I have to do is:
DefaultStyleKey = typeof(MyControl);
NOTE: It does render in Expression Blend though.
Upvotes: 0
Views: 452
Reputation: 14256
Did you add this attribute to your assembly:
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries))]
This is usually put into the AssemblyInfo.cs file. It tells WPF where to look for your generic.xaml file.
Upvotes: 0
Reputation: 8763
Is your VS designer crashes or it shows nothing but a plain border like appearance.
I would suggest. You have a separate style for the control, relatively light weight. Apply that style from constructor of the control by checking whether IsInDesignTime.
If, your designer crashes or displays some error. Then, you should try design time debugging.
Also, in few cases. If, the application type is ".NetFramework 4 Client Profile" [Which is the default, wpf application type in VS2010] you might get some wired things like this.
HTH
Upvotes: 0
Reputation: 29266
Is that constructor static? if not, it should be. The OverrideMetadata
call should live in a static constructor to work properly. change or add your constructor like this:
static MyControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetadata(typeof(MyControl)));
}
Upvotes: 1