简体   繁体   English

在 WPF 中,显示图像网格的正确方法是什么?

[英]In WPF, what is the correct way to display a grid of images?

I'm trying to make a basic tile map edior and I want to display each tile from the loaded tileset in some sort of grid, so that new tiles are added on the same row until the row is full, and then start filling the next row.我正在尝试制作一个基本的瓦片地图编辑器,我想在某种网格中显示加载的瓦片集中的每个瓦片,以便在同一行上添加新的瓦片,直到该行已满,然后开始填充下一个排。 I've added an image to better illustrate what I what:我添加了一张图片以更好地说明我的内容:

在此处输入图片说明

Should i use a modified ListView of some sort, or perhaps a canvas?我应该使用某种修改过的 ListView 还是画布? The panel containing the tiles is resizible, and i would love the tiles to rearange depending on the size of the panel.包含瓷砖的面板是可调整大小的,我希望瓷砖根据面板的大小重新排列。

You can reach this by using an ItemsControl with a UniformGrid as ItemsTemplate like您可以通过使用带有UniformGrid作为ItemsTemplateItemsControl来实现此ItemsTemplate

<ItemsControl ItemsSource="{Binding Items}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <!-- Present your item here -->
        </DataTemplate>
    </ItemsControl.Itemtemplate>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="5"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM