简体   繁体   中英

Wpf Custom Control problem

I have strange problem with WPF custom control that I have made. When I drag and drop WPF custom control from toolbox to design surface I only see one border without any controls in it... I have another same WPF custom control project with same custom control and same code and when I reference that project everything works fine.

I have template in theme folder that is called DatePicker.Generic.Xaml and I have defined

<Style x:Key="{x:Type DateControls:DatePicker}" 
       TargetType="{x:Type DateControls:DatePicker}">

where DateControls is xml namespace of my DatePicker custom control. I have also added

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

in assemblyinfo file. Can someone help? Thanks

检查您的控件代码是否具有静态构造函数,该构造函数使用适当的类型参数调用DefaultStyleKeyProperty.OverrideMetadata(如果在VS中添加新的自定义控件,则会为您生成该代码)。

You may want to look at the ComponentResourceKey Markup Extension. Look at the TypeInTargetAssembly and ResourceId argument (of componentresourcekey)'s when you set the Style element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM