开发者

Databound Canvas control in Silverlight

开发者 https://www.devze.com 2022-12-21 04:50 出处:网络
Is it possible to have the controls on a canvas be bound to a list of objects?I am thinking something like this:

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消