Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF window width does not adjust properly when ListView scrollbars are removed

$
0
0

I have a WPF project developed with VS 2008 that is using version 3.5 of the .NET framework.  The initial window width is set to 680 and SizeToContent is set to "Width" only.  There are 3 ListView controls that are placed in a grid panel in this window.  Each column definition in the grid has the Width="*".  I want the window to be resized according to the width in all 3 ListView controls.

When the ListView controls are initially filled with data, the window is properly sized.  If additional data comes in to any of the ListView controls, then the window shrinks or grows the width appropriately based upon the size of the longest column data, which is what I want.

The initial data displayed includes scrollbars in the first 2 ListView controls.  If the window is vertically expanded such that the horizontal scrollbars no longer appear, then the width of the ListView control is properly resized.  But, the window horizontal size is not correctly updated.  It is clear that the space left over at the end of the window matches the horizontal size of the scrollbar that was just removed.  Does anyone have any ideas as to how I can get the window to resize properly when a vertical scrollbar is removed from a ListView control?

Here is my XAML:

<Window
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 xmlns:local ="clr-namespace:AttackPoker2"    
 x:Class="AttackPoker2.MainWindow"
 x:Name="LobbyWindow"
 Title="Attack Poker Lobby"
 Height="480" mc:Ignorable="d" SizeToContent="Width"
 MinWidth="680" MinHeight="480" SizeChanged="LobbyWindow_SizeChanged" Loaded="LobbyWindow_Loaded" Closing="LobbyWindow_Closing" StateChanged="LobbyWindow_StateChanged"><Window.Background><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="#FF434D7A" Offset="0"/><GradientStop Color="#FF180CFA" Offset="1"/></LinearGradientBrush></Window.Background>
 ...<Grid><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="*"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="0.064*"/><RowDefinition Height="0.936*"/></Grid.RowDefinitions><!-- Define the selected table label. --><Label x:Name="SelTableLabel" Margin="1,-5,0,0" Content="Table" FontSize="11" Foreground="#FF000000" Background="#FFFFFFFF"
      Grid.Row="0" Grid.Column="2" FontFamily="Georgia" FontWeight="Bold" VerticalAlignment="Bottom"/><ListView x:Name="ListView1" ItemContainerStyle="{StaticResource alternatingListViewItemStyle}" AlternationCount="2" SelectionChanged="ListView1_SelectionChanged"
        Grid.Row="1" Grid.Column="0" SelectionMode="Multiple" ItemsSource = "{Binding ElementName=LobbyWindow, Path=ListCollection1}"><ListView.View><GridView><GridViewColumn DisplayMemberBinding="{Binding Game}"><GridViewColumnHeader Content="Game" FontWeight="Bold" /></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding Stakes}"><GridViewColumnHeader Content="Stakes" FontWeight="Bold" /></GridViewColumn><GridViewColumn Width="30" DisplayMemberBinding="{Binding Seats}"><GridViewColumnHeader Content="Seats" FontWeight="Bold" /></GridViewColumn></GridView></ListView.View></ListView><ListView x:Name="ListView2" ItemContainerStyle="{StaticResource alternatingListViewItemStyle}" AlternationCount="2"
        Grid.Row="1" Grid.Column="1" SelectionChanged="ListView2_SelectionChanged" SelectionMode="Single" ItemsSource = "{Binding ElementName=LobbyWindow, Path=ListCollection2}"><ListView.View><GridView><GridViewColumn Width="90" x:Name="TableName" DisplayMemberBinding="{Binding TableName}"><GridViewColumnHeader Content="Table" Width="90" FontWeight="Bold" HorizontalAlignment="Left" /></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding Stakes}"><GridViewColumnHeader Content="Stakes" FontWeight="Bold" /></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding NumPlayers}"><GridViewColumnHeader Content="Players" FontWeight="Bold" /></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding Speed}"><GridViewColumnHeader Content="Speed" FontWeight="Bold" /></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding HandsPerHour}"><GridViewColumnHeader Content="H/Hr" FontWeight="Bold" /></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding AvgPotSize}"><GridViewColumnHeader Content="Avg Pot" FontWeight="Bold" /></GridViewColumn></GridView></ListView.View></ListView><ListView x:Name="ListView3" ItemContainerStyle="{StaticResource alternatingListViewItemStyle}" AlternationCount="2"
       Grid.Row="1" Grid.Column="2" SelectionMode="Single" ItemsSource = "{Binding ElementName=LobbyWindow, Path=ListCollection3}"><ListView.View><GridView><GridViewColumn DisplayMemberBinding="{Binding Player}"><GridViewColumnHeader Content="Player" FontWeight="Bold" /></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding City}"><GridViewColumnHeader Content="City" FontWeight="Bold" /></GridViewColumn><GridViewColumn DisplayMemberBinding="{Binding Chips}"><GridViewColumnHeader Content="Chips" FontWeight="Bold" /></GridViewColumn></GridView></ListView.View></ListView></Grid>     </Window>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>