WPF WrapPanel - 所有项目应具有相同的宽度 [英] WPF WrapPanel - all items should have the same width

查看:19
本文介绍了WPF WrapPanel - 所有项目应具有相同的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListBox,我用 WrapPanel 替换了它的 ItemsPanel.WrapPanel 现在托管数据绑定的 ListboxItems.每个项目都有一个可变大小的文本,为每个项目提供不同的宽度.但是,我希望宽度保持不变,以便所有项目与具有最长文本的项目具有相同的宽度.这可能吗?

I have a ListBox whose ItemsPanel I have replaces with a WrapPanel. The WrapPanel now hosts the databound ListboxItems. Each item has a variable sized text in it, giving each item a different width. However, I want the width to be constant so that all items have the same width as the item with the longest text. Is that possible?

推荐答案

将每个项目放置在单行单列(自动宽度)网格中,并为列命名.在 ListBox 上设置 Grid.IsSharedSizeScope,所有网格都将具有相同的宽度.

Place each item in a single-row, single-column (auto width) grid, and name the column. Set Grid.IsSharedSizeScope on the ListBox and all grids will have the same width.

这篇关于WPF WrapPanel - 所有项目应具有相同的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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