代码之家  ›  专栏  ›  技术社区  ›  Nikos Tsokos

在某些配置中,列表框的滚动条在WPF中消失

  •  1
  • Nikos Tsokos  · 技术社区  · 15 年前

    当一个列表框被放置在2*2的网格中时,我成功地在它的自动滚动查看器功能中重现了一个奇怪的行为。

    如果您尝试按原样使用以下xaml,您将看到垂直scrollviewer在那里,但不可见(它只是超出了第一列的宽度)

    <Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="200" Width="200">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
    
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>
    
        <ListBox Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" >
            <ListBox.Items>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
                <TextBlock Text="Item"/>
            </ListBox.Items>
        </ListBox>
    
        <Canvas Background="Yellow" Grid.Row="0" Grid.Column="1" MinHeight="20"/>
        <Canvas Background="Red" Grid.Row="1" Grid.Column="1" MinHeight="20"/>
    
    </Grid>
    

    据我所知,有问题的控件是第一块画布(黄色的)。

    这个问题对其他人或我来说是可复制的吗?

    1 回复  |  直到 15 年前
        1
  •  1
  •   Abel    15 年前

    是的,它是可复制的,实际上,它在每个网格、位置或大小上都是可复制的。将实际高度添加到列表框时,滚动条将返回。

    然而,真正的问题似乎来自黄色画布,它与列表框重叠。不管那是不是虫子,我不知道。去掉黄色的帆布,你就没事了。将行从 0 1 你也很好。但是,如上所述,当您为列表框指定特定高度时,滚动条也会返回:

    <ListBox Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Height="100">
        <ListBox.Items>
            <TextBlock Text="Item 1"/>
            <TextBlock Text="Item 2"/>
            <TextBlock Text="Item 3"/>
            <TextBlock Text="Item 4"/>
            <TextBlock Text="Item 5"/>
            <TextBlock Text="Item 6"/>
            <TextBlock Text="Item 7"/>
            <TextBlock Text="Item 8"/>
            <TextBlock Text="Item 9"/>
            <TextBlock Text="Item 10"/>
            <TextBlock Text="Item 11"/>
            <TextBlock Text="Item 12"/>
        </ListBox.Items>
    </ListBox>
    
    推荐文章