views:

760

answers:

1

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>
+2  A: 

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

ref: codeplex thread

qntmfred