我创建了一个UserControl,希望它可以用作其他元素的容器,即,我希望能够向其添加子元素.例如,如果我只想要一个具有特殊样式的边框和标题的UserControl,那么我想向其中添加内容.这就是我创建的,一个具有某些属性的高级矩形,使其可以像某种面板一样工作. 如何实现此目的? 关于Simeon
I've created a UserControl that I want to be able to work as a container for other elements, i.e. I want to be able to add childs to it. For example if I just want a UserControl that is a specially styled border and a heading, so I want to add content into it. That's what I've created, an advanced rectangle with some properties that make it work as a sort of panel.How do I accomplish this?Regards, Simeon
推荐答案
您可能只想将面板添加到自定义控件并公开其Children属性.通过您的用户控件.您还可以公开自己的集合,例如UIElementCollection甚至是ObservableCollection.
You may just want to add your panel to the custom control and expose its Children property via your user control. You could also expose a collection of your own, like a UIElementCollection or maybe even an ObservableCollection.
此外,您可能想要添加ContentPropertyAttribute 到您的用户控件.
Additionally, you may want to add teh ContentPropertyAttribute to your user control.
-Jer
更多推荐
WPF用户控件中的子容器
发布评论