Shi*_*mmy 10 wpf grid xaml wrappanel itemspaneltemplate
<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>
Run Code Online (Sandbox Code Playgroud)
我想要的是右栏中的项目应该被布置为填充窗口宽度,然后创建一个新的行,这正是WrapPanel的制作.
问题是,WrapPanel只在一行中显示项目,在下面显示水平滚动条,而所有项目在右侧"隐藏"超过窗口大小.
我怎么能防止这种情况?
Jin*_*ung 16
您需要使第二个ListBox的水平滚动条禁用.
<ListBox ItemsSource="{Binding}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...>
....
</ListBox>
Run Code Online (Sandbox Code Playgroud)
编辑
另外,你有理由将ScrollViewer用作第一个ListBox吗?为什么我要问的是ListBox内部已经有ScrollViewer,默认的Visibility是Auto.