本文介绍了WPF的ListView变宽响应调整列,但不退缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下.NET 3.5 XAML,如果拖动的日列更宽的列宽,在ListView很好的增长考虑到这一点。如果然后拖动列宽度窄,但是,该表保持,因为它是相同的大小。

这同样的问题垂直方面也存在。如果你的一些列具有自动换行,该表将获得更高来处理这个问题,但毫不退缩。

下面是真正愚蠢的一部分。如果删除ListView.ItemsSource部分,然后在ListView的工作原理希望!为什么会这样有影响吗?

任何想法?

 <窗​​口x:类=TestWpfTables.Window1
    的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
    的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
    XMLNS:S =CLR的命名空间:System.Collections中;装配= mscorlib程序
    的xmlns:P =CLR的命名空间:系统;装配= mscorlib程序
    标题=窗口1高度=300宽度=300>
    <电网>
        < ListView控件的Horizo​​ntalAlignment =左>
            < 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控件>
    < /网格>
< /窗>
 

解决方案

裁判:codePLEX线程

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>
解决方案

ref: codeplex thread

这篇关于WPF的ListView变宽响应调整列,但不退缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 07:27
查看更多