我有一个用户控件,我希望能够拥有多个孩子。它已经有了 StackPanel 作为它的孩子,所以我做错了什么?
最终,我希望控件自动包含一些它自己的子元素,然后在使用它时允许在其中一个元素中放置更多的子元素。我尝试了 MSDN 的 How to Override the Logical Tree但没有成功。
提前致谢。
LayerPanelItem.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>
主要.xaml:
<controls:LayerPanelItem>
<TextBlock>Test</TextBlock>
<TextBlock>Test</TextBlock> <!-- Error: The property 'Content' is set more than once. -->
</controls:LayerPanelItem>