使用 Blend 访问嵌套的 UserControl 的 ContentPresenter
我在 Blend 中创建了一个简单的 UserControl,其中包含(除其他外)一个 ContentPresenter。
我希望能够将此 UserControl 放到另一个 UserControl 上,然后将其他控件添加到其 ContentPresenter 中,但是当我将其包含在第二个 UserControl 中时,我看不到执行此操作的方法。
使用 Blend,如何公开底层 ContentPresenter,以便可以直观地设置其内容(即:以便它们在“对象和时间线”窗口中显示为子控件)?
I've created a simple UserControl in Blend which contains (amongst other things) a ContentPresenter.
I'd like to be able to drop this UserControl onto another UserControl and then add other controls into its ContentPresenter, but when I include it in the second UserControl I can't see a way to do this.
Using Blend, how do I expose the underlying ContentPresenter so that its contents can be set visually (ie: so they appear as child controls in the Objects and Timeline window)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它是内容控件,要添加子控件,请将它们设置为控件的内容
编辑:现在我想到了,您可能需要做一些事情来使 Content 属性成为默认属性,该属性由您的内部 xaml 填充控制,我记不清它到底是什么,但如果你的 xaml 看起来像这样(如下),那么无论如何
Edit2
您的
MyUserControl
需要一个object
类型的MyContent
属性,并且它必须以某种方式显示该属性的值。您也许可以在 MyContent 属性的设置器中创建它,但它看起来“hacky”If it’s a content control, to add child controls you set them as the content of the control
Edit: now that I think about it you might need to do something to make the Content property the default property which is populated by the inner xaml of your control, I can't remember exactly what it was but if your xaml looks like this (below) it doesn't matter anyway
Edit2
Your
MyUserControl
would need aMyContent
property of typeobject
and it'd have to somehow display the value of that property. You might be able to create it in the setter of the MyContent property but it seems "hacky"