如何创建一个自定义控件,该控件接受 UIElement
列表并根据某些逻辑进行渲染?
由于它将处理 UIElement
列表,因此添加控件的最佳方式将与 ListBox
或 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的位置?