WPF bug? Grid's column does not accommodate ListBox scrollbar

拈花ヽ惹草 提交于 2019-12-11 12:42:20

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1313341/wpf-bug-grids-column-does-not-accommodate-listbox-scrollbar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!