gpt4 book ai didi

wpf - WrapPanel 将项目布置在一条长水平线(显示滚动条)中,而不是换行

转载 作者:行者123 更新时间:2023-12-04 17:29:07 27 4
gpt4 key购买 nike

<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 仅将项目布置在一行中,在下方显示一个水平滚动条,而所有项目都“隐藏”在右侧,超出了窗口的大小。

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

最佳答案

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

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

编辑

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

关于wpf - WrapPanel 将项目布置在一条长水平线(显示滚动条)中,而不是换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7928434/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com