如何创建一个自定义控件,该控件采用UIElement
s 列表并根据某些逻辑呈现它们?
因为它将处理UIElement
s 的列表,所以添加控件的最佳方法将与 for 相同,即ListBox
or ComboBox
。
<local:SomeControl>
<Button Content="First"/>
<Label Content="Something other"/>
</local:SomeControl>
这是用户控件的 XAML:
<UserControl x:Class="_2009_07_22_Wpf_Smooth_Scroller.SomeControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
MinHeight="100" MinWidth="100">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Content="Some title"/>
<!-- The inner UIElement to add content to -->
<Canvas x:Name="innerPanel" Grid.Row="1"/>
</Grid>
</UserControl>
例如,我怎样才能将第 i 个控件放置到位置 X = 50 * i, Y = 40 * i ?