11
<Grid.ColumnDefinitions>
  <ColumnDefinition Width="Auto"/>
  <ColumnDefinition />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
  <RowDefinition Height="Auto"/>
  <RowDefinition/>
  <RowDefinition Height="40"/>
</Grid.RowDefinitions>

<c:SearchTextBox Grid.ColumnSpan="2" .../>

<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
  <ListBox 
    ItemsSource="{Binding Categories}" 
    IsSynchronizedWithCurrentItem="True" 
    ... />
</ScrollViewer>

<!-- Here is what I'm talking about:-->
<ListBox ItemsSource="{Binding Products}"
  IsSynchronizedWithCurrentItem="True" Grid.Column="1" Grid.Row="1">
  <ListBox.ItemsPanel>
    <ItemsPanelTemplate>
      <WrapPanel />
    </ItemsPanelTemplate>
  </ListBox.ItemsPanel>
</ListBox>

我想要的是右列中的项目应布置为填充窗口宽度,然后创建一个新行,这正是 WrapPanel 的用途。
问题是,WrapPanel 仅将项目布置在一行中,显示下方的水平滚动条,而所有项目都“隐藏”在右侧,超出了窗口的大小。

我怎样才能防止这种情况?

4

1 回答 1

18

您需要禁用第二个 ListBox 的水平滚动条。

<ListBox ItemsSource="{Binding}" 
         ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...>
....
</ListBox>

编辑

另外,您有理由将 ScrollViewer 用于第一个 ListBox?为什么我要问的是 ListBox 内部已经有 ScrollViewer,其中默认 Visibility 是 Auto。

于 2011-10-28T11:30:24.327 回答