Creating container usercontrol with design time su

2019-06-13 20:04发布

问题:

I want to create a container usercontrol with design time support in WPF ? How can I do ?

回答1:

If you want to have a container user control with design time support, you can create a ContentControl http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx to host other user controls inside your container control.

You can expose the content control as a public property and then assign any other user controls you create to this property to display within the ContentControl. You would have the design time support of the parent control or any child user controls by default since they would all just be user controls.



回答2:

Declare the following in your UserControl at the top:

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]  
public partial class ExpanderControl : UserControl 

Required NameSpaces:

using System.ComponentModel;
using System.ComponentModel.Design;