ListBox content does not resize when window is made smaller

Posted by DamonGant on Stack Overflow See other posts from Stack Overflow or by DamonGant
Published on 2012-03-31T05:26:05Z Indexed on 2012/03/31 5:28 UTC
Read the original article Hit count: 170

Filed under:
|

I'm using .NET 4.0 (not .NET 4.0 CP) and have run into this kinda unique issue. I created a ListBox to display bound elements, first off here is (a part) of my XAML.

<Grid Grid.Row="2" Background="#EEEEEE">
        <Border Margin="6,10,10,10" BorderBrush="#666666" BorderThickness="1">
            <ListBox ItemsSource="{Binding}" Name="appList" BorderThickness="0" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Border Grid.Column="0" Margin="5" BorderThickness="3" CornerRadius="2" BorderBrush="Black" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="ItemBorder">
                                <Image Width="64" Height="64"  Source="{Binding Path=IconUri}" Stretch="UniformToFill" />
                            </Border>
                            <StackPanel Margin="0,5,5,5" Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Stretch">
                                <TextBlock FontSize="18" Text="{Binding Path=DisplayName}" />
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="60"/>
                                    </Grid.ColumnDefinitions>
                                    <ProgressBar Grid.Column="0" Height="24" HorizontalAlignment="Stretch" IsIndeterminate="{Binding Path=IsDiscovering}" Value="{Binding Path=PercentageDownloaded}" />
                                    <TextBlock Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"><TextBlock x:Name="percentageDownloaded" /><TextBlock x:Name="percentageMeter">%</TextBlock></TextBlock>
                                </Grid>
                            </StackPanel>
                        </Grid>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Path=IsDiscovering}">
                                <DataTrigger.Value>True</DataTrigger.Value>
                                <Setter TargetName="percentageDownloaded" Property="Text" Value="N/A" />
                                <Setter TargetName="percentageMeter" Property="Visibility" Value="Collapsed" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=IsDiscovering}">
                                <DataTrigger.Value>False</DataTrigger.Value>
                                <Setter TargetName="percentageDownloaded" Property="Text" Value="{Binding Path=PercentageDownloaded}" />
                                <Setter TargetName="percentageMeter" Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ListBox>
        </Border>
    </Grid>

Sizing the window up stretches the ListBox content just fine, but when I size it down, it retains it's width and spawns vertical scrollbars.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml