Is it possible to have the controls on a canvas be bound to a list of objects? I am thinking something like this:
<UserControl开发者_运维问答.Resources>
<DataTemplate x:Key="MyItemTemplate">
<ContentControl Content="{Binding Converter={StaticResource MyControlConverter}}"></ContentControl>
</DataTemplate>
</UserControl.Resources>
<Canvas ItemsSource="{Binding MyItems}" ItemTemplate="{StaticResource MyItemTemplate}">
</Canvas>
Where MyItems is this:
public List<Tuple<ControlType, Point>> MyItems;
Basically, there would be a converter that converted each Tuple object to a control at the given Point coordinates on the canvas. I know that there isn't an "ItemsSource" or "ItemsTemplate" property on the Canvas control, but is this possible in some other way?
You add a listbox and set its itemspanel to be a canvas.
<ListBox ItemsSource="{Binding MyItems}" ItemTemplate="{StaticResource MyItemTemplate}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
精彩评论