【问题标题】:listbox bounded to collection, with table layout where each cell is an item of the collection列表框绑定到集合,具有表格布局,其中每个单元格都是集合的一个项目
【发布时间】:2011-05-24 11:08:49
【问题描述】:

我正在尝试创建一个包含 x 列和 y 行的表。 此表可以有一个项目源,并且此表中的每个单元格都是一个项目。 例如,如何将图像集合绑定到每个图像都是一个项目的表。 如果有人可以用 liskbox 实现这一点就更好了

这是我的代码:

<ListBox Grid.Row="2">
    <ItemsControl ItemsSource="{Binding Projects, Mode=TwoWay}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <toolkit:WrapPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Image Source="{Binding Path=ProjectIcon, Mode=TwoWay}" Height="30" Width="30"  />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</ListBox>

【问题讨论】:

    标签: silverlight datagrid listbox grid


    【解决方案1】:

    您要查找的控件是 Silverlight 中的 WrapPanel Toolkit

     <ItemsControl ItemsSource="{Binding ImageSet}">
        <ItemsControl.ItemsPanel>
           <ItemsPanelTemplate>
                <toolkit:WrapPanel />
           </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
           <DataTemplate>
              <Image Source="{Binding}" />
           </DataTemplate>
        </ItemsControl.ItemTemplate>
     </ItemsControl>
    

    【讨论】:

    • 谢谢。当您编写项目控件时,您的意思是我可以编写一个列表框来代替它?以及如何在此控件中指定我希望每行中有 4 个项目?
    • @Pavel:将 ItemsControl 的宽度设置为单个项目宽度的 4 倍。但是,您真的有充分的理由将自己限制在 4 人以内吗?
    • 它还写信给我说找不到类型“WrapPanel”,因为schemas.microsoft.com/winfix/2006/xaml/presentation/toolkit 是一个未知的命名空间。出了什么问题?
    • @pavel:你还没有安装工具包,然后引用了 System.Windows.Controls.Toolkit.dll?
    • 首先感谢您之前的所有回答。我还有一个问题,我只有一行有很多列。问题是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 2010-12-08
    • 2013-07-13
    • 2016-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多