WPF bug? Grid's column does not accommodate Li

2019-07-27 09:45发布

In the following example, the leftmost column's width does not increase to accommodate the ListBox's scrollbar that appears when the UserControl's height is decreased:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Example">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Grid.ColumnSpan="2">Example text</TextBlock>
        <ListBox Grid.Row="1" Grid.Column="0">
            <ListBoxItem>One</ListBoxItem>
            <ListBoxItem>Two</ListBoxItem>
            <ListBoxItem>Three</ListBoxItem>
            <ListBoxItem>Four</ListBoxItem>
            <ListBoxItem>Five</ListBoxItem>
        </ListBox>
        <Expander Grid.Row="1" Grid.Column="1" Header="Expander" />
    </Grid>
</UserControl>

When the TextBlock with the ColumnSpan attribute is removed the column resizes as expected. Is this a bug in WPF?

标签: wpf grid resize
1条回答
smile是对你的礼貌
2楼-- · 2019-07-27 10:26

It appears this is a known bug with the ListBox scrollbar and the WPF Grid. Microsoft also notes they will probably not have this fixed in 4.0.

查看更多
登录 后发表回答