gpt4 book ai didi

具有多个子级的 WPF UserControl

转载 作者:行者123 更新时间:2023-12-03 17:21:08 24 4
gpt4 key购买 nike

我有一个 UserControl,我希望能够拥有多个 child 。它已经有了 StackPanel 作为它的 child ,所以我做错了什么?

最终,我希望控件自动包含一些自己的子项,然后在使用时允许在其元素之一中放置更多子项。我试过 MSDN's How to Override the Logical Tree没有成功。

提前致谢。

图层面板项.xaml:

<UserControl x:Class="Controls.LayerPanelItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel></StackPanel>
</UserControl>

主文件:
<controls:LayerPanelItem>   
<TextBlock>Test</TextBlock>
<TextBlock>Test</TextBlock> <!-- Error: The property 'Content' is set more than once. -->
</controls:LayerPanelItem>

最佳答案

您不能(直接)使用 UserControl 执行此操作。相反,您需要从 ItemsControl 派生,并将您自己的自定义布局逻辑放在子类中。

关于具有多个子级的 WPF UserControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2277309/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com