WPF的ListView变宽响应调整列,但不退缩 [英] WPF ListView grows wider in response to resizing column, but does not shrink back
问题描述
在以下.NET 3.5 XAML,如果拖动的日列更宽的列宽,在ListView很好的增长考虑到这一点。如果然后拖动列宽度窄,但是,该表保持,因为它是相同的大小。
这同样的问题垂直方面也存在。如果你的一些列具有自动换行,该表将获得更高来处理这个问题,但毫不退缩。
下面是真正愚蠢的一部分。如果删除ListView.ItemsSource部分,然后在ListView的工作原理希望!为什么会这样有影响吗?
任何想法?
<窗口x:类=TestWpfTables.Window1
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
XMLNS:S =CLR的命名空间:System.Collections中;装配= mscorlib程序
的xmlns:P =CLR的命名空间:系统;装配= mscorlib程序
标题=窗口1高度=300宽度=300>
<电网>
< ListView控件的HorizontalAlignment =左>
< ListView.View>
< GridView控件>
< GridViewColumn DisplayMemberBinding ={绑定路径=天}标题=日/>
< / GridView的>
< /ListView.View>
< ListView.ItemsSource>
< S:ArrayList的>
<电话号码:日期时间> 1990年1月1日12:22:02< / P:日期时间>
<电话号码:日期时间> 1990年1月2日13:2:01< / P:日期时间>
<电话号码:日期时间> 1990年1月5日2:1:6≤/ P:日期时间>
< / S:ArrayList的>
< /ListView.ItemsSource>
< / ListView控件>
< /网格>
< /窗>
在一般情况下,所有的WPF ItemsControls都长大只,这意味着我们做了初步布局传递,随后控制将只调整如果内容变化较大。我们不调整默认较小的原因是,它需要一个昂贵的措施,并安排通,这将性能产生负面影响
In the following .NET 3.5 XAML, if you drag the column width of the 'Day' column wider, the ListView nicely grows to account for this. If you then drag the column width narrower, however, the table stays the same size as it was.
This same problem exists vertically, too. If some of your columns have word wrap, the table will get taller to handle this, but then not shrink back.
Here's the really goofy part. If you remove the ListView.ItemsSource section, then the ListView works as desired! Why would this affect it?
Any ideas?
<Window x:Class="TestWpfTables.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:p="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Grid>
<ListView HorizontalAlignment="Left">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Day}" Header="Day" />
</GridView>
</ListView.View>
<ListView.ItemsSource>
<s:ArrayList>
<p:DateTime>1990/1/1 12:22:02</p:DateTime>
<p:DateTime>1990/1/2 13:2:01</p:DateTime>
<p:DateTime>1990/1/5 2:1:6</p:DateTime>
</s:ArrayList>
</ListView.ItemsSource>
</ListView>
</Grid>
</Window>
In general, all WPF ItemsControls are "grow-only", meaning that we do the initial layout pass and subsequently the control will only resize larger if the content changes. The reason we don't resize smaller by default is that it would require an expensive measure and arrange pass, which would negatively impact performance
这篇关于WPF的ListView变宽响应调整列,但不退缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!