【问题标题】:Databound Canvas control in SilverlightSilverlight 中的数据绑定画布控件
【发布时间】:2010-02-26 22:18:44
【问题描述】:

是否可以将画布上的控件绑定到对象列表?我在想这样的事情:

<UserControl.Resources>
    <DataTemplate x:Key="MyItemTemplate">
        <ContentControl Content="{Binding Converter={StaticResource MyControlConverter}}"></ContentControl>
    </DataTemplate>
</UserControl.Resources>
<Canvas ItemsSource="{Binding MyItems}" ItemTemplate="{StaticResource MyItemTemplate}">
</Canvas>

MyItems 在哪里:

public List<Tuple<ControlType, Point>> MyItems;

基本上,会有一个转换器将每个 Tuple 对象转换为画布上给定 Point 坐标处的控件。我知道 Canvas 控件上没有“ItemsSource”或“ItemsTemplate”属性,但这是否可以通过其他方式实现?

【问题讨论】:

    标签: silverlight data-binding canvas


    【解决方案1】:

    您添加一个列表框并将其项目面板设置为画布。

    <ListBox ItemsSource="{Binding MyItems}" ItemTemplate="{StaticResource MyItemTemplate}">
       <ListBox.ItemsPanel>
          <ItemsPanelTemplate>
             <Canvas/>
          </ItemsPanelTemplate>
       </ListBox.ItemsPanel>
    </ListBox>
    

    【讨论】:

      猜你喜欢
      • 2011-08-24
      • 2013-03-30
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 2013-12-11
      相关资源
      最近更新 更多