在网格中排列集合项目 [英] Arranging collection items in a grid

查看:29
本文介绍了在网格中排列集合项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将集合中的项目排列在具有特定列数和行数(例如 4x6)的网格中.每个项目都公开了依赖属性(整数)X 和 Y,并且应该放置在网格的相关单元格中.请注意,集合在运行时可能会发生变化,这应该会更新网格项目.

I would like to arrange items of a collection in a grid with a specific number of columns and rows (say 4x6). Each item exposes the dependency properties (integer) X and Y and should be placed in the relevant cell of the grid. Note that the collection can change during runtime which should update the grid items.

我找不到任何好的解决方案.但也许不使用代码隐藏甚至是可能的?

I couldn't find any good solution. But maybe it is even possible without using the code-behind?

不介意转换之类的.这东西无论如何都会改变.使用的集合类并不重要.(你可以选择一个.)

Don't mind conversion or something. This stuff changes anyway. The used collection class isn't important. (You can choose one.)

我该如何解决这个问题?我们欢迎任何适当的建议,谢谢.

How can I solve this problem? Any appropriate suggestions would we welcome, thanks.

推荐答案

<ItemsControl ItemsSource="{Binding YourItems}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Grid/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
        <Style>
            <Setter Property="Grid.Column" Value="{Binding X}"/>
            <Setter Property="Grid.Row" Value="{Binding Y}"/>
        </Style>
    </ItemsControl.ItemContainerStyle>
</ItemsControl>

这篇关于在网格中排列集合项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆