类似于Stackpanel,在那里我可以将诸如文本框和按钮之类的控件作为内部XAML:
<StackPanel>
<Button Content="OK">
<Button Content="Cancel">
<Button Content="Apply">
</StackPanel>
我需要的是:
<myControls:myOptionsList>
<Button Content="OK">
<Button Content="Cancel">
<Button Content="Apply">
</myControls:myOptionsList>
答案 0 :(得分:2)
假设您的UserControl有一个内部Panel元素,应在其中放置其他元素,即:
<UserControl x:Class="YourNamespace.OptionsControl" ...>
<Grid>
<GroupBox Header="Options">
<StackPanel x:Name="optionsPanel"/>
</GroupBox>
</Grid>
</UserControl>
您可以简单地将Panel的Children
属性作为UIElementCollection属性公开,该属性被标记为UserControl的ContentProperty
:
[ContentProperty(nameof(Options))]
public partial class OptionsControl : UserControl
{
public UIElementCollection Options
{
get { return optionsPanel.Children; }
}
...
}