tags:

views:

27

answers:

1

Hello,

I have a listview and I need to have width of first column automatic (so the width is properly measurized) and second column that will take the rest of space in the head of listview.

How can I do that?

My XAML looks like this right now:

    <ListView HorizontalAlignment="Stretch" ItemsSource="{Binding ListViewItemsSource}"
              Margin="5,0,5,5" DockPanel.Dock="Top" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Plugin" DisplayMemberBinding="{Binding Plugin}" />
                <GridViewColumn Header="Message">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate x:Name="col1Template">
                            <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Message}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

Thank you!

+1  A: 

This behaviour is not present in the ListView - if width is left blank it will try to size as best as it can initially (often without data => according to header). If you need it badly - you could try the DataGrid instead which has full support for sizing columns.

Goblin
Thank you! I've found how to work with DataGrid here: http://www.switchonthecode.com/tutorials/using-the-wpf-toolkit-datagrid -- let's note for other people that if you use .NET 3.5sp1 then you have to use WPF Toolkit (but it's covered in the article)
MartyIX