WPF Lookless控件没有在VS设计器中显示

时间:2010-08-18 14:32:29

标签: wpf custom-controls

我有一个我构建的无外观控件,它在我的Themes目录中的generic.xaml中定义了默认样式。我在构造函数中也有以下内容。

 static MyControl()
 {
     DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetadata(typeof(MyControl)));
 }

 public MyControl()
 {
     //DoSomeWork
 }

我想在WPF中设置其他东西吗?在Silverlight中我所要做的就是:

DefaultStyleKey = typeof(MyControl);

注意:它确实在Expression Blend中渲染。

3 个答案:

答案 0 :(得分:1)

那个构造函数是静态的吗?如果没有,它应该是。 OverrideMetadata调用应该存在于静态构造函数中以正常工作。像这样改变或添加你的构造函数:

static MyControl()
 {
     DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetadata(typeof(MyControl)));
 }

答案 1 :(得分:0)

你的VS设计师是否崩溃,或只显示外观等简单边框。

我会建议。你有一个独立的控制风格,相对较轻的重量。通过检查是否IsInDesignTime。

从控件的构造函数应用该样式

如果,您的设计师崩溃或显示一些错误。然后,你应该尝试设计时调试。

此外,在少数情况下。如果,应用程序类型是“.NetFramework 4 Client Profile”[这是VS2010中的默认wpf应用程序类型],您可能会收到类似这样的有线信息。

HTH

答案 2 :(得分:0)

您是否已将此属性添加到程序集中:

[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))]

这通常放在AssemblyInfo.cs文件中。它告诉WPF在哪里查找generic.xaml文件。

相关问题