0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I've found how to work with DataGrid here: 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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.