使用 Blend 访问嵌套的 UserControl 的 ContentPresenter

发布于 2024-10-31 17:19:27 字数 270 浏览 6 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏别ゝ 2024-11-07 17:19:27

如果它是内容控件,要添加子控件,请将它们设置为控件的内容

<MyContentControl>
    <Grid x:Name=”ImAChild”>
    </Grid>
</MyContentControl>

编辑:现在我想到了,您可能需要做一些事情来使 Content 属性成为默认属性,该属性由您的内部 xaml 填充控制,我记不清它到底是什么,但如果你的 xaml 看起来像这样(如下),那么无论如何

<MyContentControl>
    <MyContentControl.Content>
        <Grid x:Name=”ImAChild”>
        </Grid>
    </MyContentControl.Content>
</MyContentControl>

Edit2
您的 MyUserControl 需要一个 object 类型的 MyContent 属性,并且它必须以某种方式显示该属性的值。您也许可以在 MyContent 属性的设置器中创建它,但它看起来“hacky”

<MyUserControl>
    <MyUserControl.MyContent>
        <Grid x:Name=”ImAChild”>
        </Grid>
    </MyContentControl.MyContent>
</MyUserControl>

If it’s a content control, to add child controls you set them as the content of the control

<MyContentControl>
    <Grid x:Name=”ImAChild”>
    </Grid>
</MyContentControl>

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

<MyContentControl>
    <MyContentControl.Content>
        <Grid x:Name=”ImAChild”>
        </Grid>
    </MyContentControl.Content>
</MyContentControl>

Edit2
Your MyUserControl would need a MyContent property of type object 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"

<MyUserControl>
    <MyUserControl.MyContent>
        <Grid x:Name=”ImAChild”>
        </Grid>
    </MyContentControl.MyContent>
</MyUserControl>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文