2010-07-14 44 views
1

我设法在列表框的自动滚动查看器功能中设置一个奇怪的行为,当它放置在2 * 2网格中时。ListBox的滚动条在某些配置中消失在WPF中

如果您尝试使用下面的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> 

的据我所知,是第一个画布(黄色)。 更具体WPF不喜欢的任何控件被放置在列= 0列= 1,并且破坏了的ScrollViewer功能。

这个问题是否可重现给任何其他人或只是我吗?

+0

我不明白这个,但我注意到以下内容。它可以使用文本块而不是画布进行复制,因此对于画布不是问题。当缩小网格时,列表框的宽度也会增加,这使我相信滚动条被添加到列表框中,问题在于网格不能调整大小。 – 2010-07-14 16:52:54

回答

1

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

但是,真正的问题似乎来自与列表框重叠的黄色画布。不管这是不是一个错误,我不知道。删除黄色的画布,你很好。将行从0更改为1,你也很好。但是,当你给ListBox一个特定的高度,如上所述,滚动条也回来了:

<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>