ListView控件列自动调整大小 [英] ListView column auto sizing
问题描述
让我们说我有以下的ListView:
Let's say I have the following ListView:
<ListView ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListView.View>
<GridView>
<GridViewColumn Header="Something"
DisplayMemberBinding="{Binding Path=ShortText}" />
<GridViewColumn Header="Description"
DisplayMemberBinding="{Binding Path=VeryLongTextWithCRs}" />
<GridViewColumn Header="Something Else"
DisplayMemberBinding="{Binding Path=AnotherShortText}" />
</GridView>
</ListView.View>
</ListView>
我想短文本列总是适合在屏幕上,并在必要时。
I'd like the short text columns to always fit in the screen, and the long text column to use the remaining space, word-wrapping if necessary.
这可能吗?
推荐答案
有没有简单的方法有GridListView要做到这一点,因为它不支持设置一个列的宽度以*(填充剩余空间)。
There is no easy way to do this with a GridListView since it doesn't support setting the width of a column to "*" (fill remaining space).
这里是讨论如何你可以通过使用的IValueConverter设置列TotalListWidth的宽度假的 - SumOfColumnWidths
Here is a discussion of how you could fake it by using an IValueConverter to set the width of the column to TotalListWidth - SumOfColumnWidths
在另一方面,有你使用的 DataGrid的呢?这将支持那种你正在寻找的布局,虽然是一个相当重的控制。它也只有在.NET 4原住民 - 虽然你可以通过得到3.5等效WPF工具包。
On the other hand, have you considered using a DataGrid instead? This will support the kind of layout you are looking for, though is a considerably heavier control. It is also only native in .NET 4 - though you can get an equivalent for 3.5 through the WPF Toolkit.
这篇关于ListView控件列自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!