3
在WPF中,您可以使用Canvas創建一個ListBox作爲ItemsPanel並將項目放置在該畫布上。做到這一點的代碼看起來是這樣的:在Silverlight2列表框如何使用Silverlight2 ItemsControl在畫布上定位項目集合?
<ListBox ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Width="200" Height="200"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Canvas.Left" Value="{Binding Path=XPos}"/>
<Setter Property="Canvas.Top" Value="{Binding Path=YPos}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
你可以做同樣的事情,最好一個ItemsControl?