在网格中布置收集项目 [英] Arranging collection items in a grid

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

问题描述

我想在一个具有特定数量的列和行(例如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天全站免登陆