WPF用户控件中的子容器 [英] Child container in WPF User Control

查看:99
本文介绍了WPF用户控件中的子容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个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用户控件中的子容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆