How to prevent the resizing of a ListView window?

I put the ListView in the middle row of the view. The view is contained in a window that has a SizeToContent parameter for WidthAndHeight. The ListView is initially empty, but the underlying ViewModel fills this list view in the process.

The average height of Grid.Row is set to * to fill in the available window size. When the ListView receives new items, at some point it will expand the size of the window instead of displaying the ScrollViewer in the ListView. How can I prevent this behavior so that the SizeToContent parameter is set to WidthAndHeight, the height of the Grid.Row is *, but does the ListView have a window size extension?

Here's the code for the window (the Workspace property will contain the ViewModel):

<Window x:Class="Views.ContainerWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="{Binding Title}" SizeToContent="WidthAndHeight"> <ContentControl Content="{Binding Workspace}"/> </Window> 

The view for the provided ViewModel is as follows:

 <UserControl x:Class="Views.SomeView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" MinHeight="450"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <TextBlock Grid.Row="0" TextWrapping="Wrap" Margin="5" Text="Some description text"/> <ListView Grid.Row="1" ItemsSource="{Binding ItemsList}" Margin="5"> <ListView.View> <GridView> ... </GridView> </ListView.View> </ListView> <Button Grid.Row="2" HorizontalAlignment="Right" Command" Value="{Binding CloseCommand}"/> </Grid> </UserControl> 
+4
source share
2 answers

Turn off windows autostart after it loads work for you?

  private void Window_Loaded(object sender, RoutedEventArgs e) { this.SizeToContent = SizeToContent.Manual; } 
+4
source

You will need to limit one of the dynamic size elements in the hierarchy. That is, set maximumheight / maximumwith or height / with windown, grid or listboxt properties to the appropriate value.

+1
source

All Articles