ItemsControl 中的 WrapPanel 添加了 ScrollViewer 导致失去换行行为
我正在 ItemsControl 内的 ItemsPanel 内使用 WrapPanel。只要添加的物品符合尺寸,这种方法就完美。为了满足内容超出尺寸的情况,我添加了ScrollViewer。但现在这些项目仅垂直列出,即使它们都适合。知道是否可能以及我必须做什么。
这是我的 xaml:
<ItemsControl Name="LicSwUserItemsCtl" Grid.Column="1" Grid.Row="2">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer Name="Scroller" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="0" Name="wrpPanel" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="BrdrStkPnlSwLicUser" CornerRadius="2" BorderThickness="1" Width="120" Height="20" Margin="0,0,3,0" BorderBrush="Transparent">
<StackPanel Name="StkPnlSwLicUser" Orientation="Horizontal" Height="18" Width="120" Margin="0" MouseEnter="StackPanel_MouseEnter" MouseLeave="StackPanel_MouseLeave" MouseLeftButtonUp="StackPanel_MouseLeftButtonUp" >
<Image Source="{Binding Converter={StaticResource IconImage}}" Margin="2,0,3,0" Height="16" Width="16" />
<TextBlock Name="txtBlk" Text="{Binding NodeText}" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
I'm working with a WrapPanel within an ItemsPanel within an ItemsControl. This works perfect as long as the items added fit the size. To meet the situations where the content exceeds the size, I added a ScrollViewer. But now the items are listed only vertically even if all they would fit. Any idea if it is possible and what I have to do.
Here is my xaml:
<ItemsControl Name="LicSwUserItemsCtl" Grid.Column="1" Grid.Row="2">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer Name="Scroller" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="0" Name="wrpPanel" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="BrdrStkPnlSwLicUser" CornerRadius="2" BorderThickness="1" Width="120" Height="20" Margin="0,0,3,0" BorderBrush="Transparent">
<StackPanel Name="StkPnlSwLicUser" Orientation="Horizontal" Height="18" Width="120" Margin="0" MouseEnter="StackPanel_MouseEnter" MouseLeave="StackPanel_MouseLeave" MouseLeftButtonUp="StackPanel_MouseLeftButtonUp" >
<Image Source="{Binding Converter={StaticResource IconImage}}" Margin="2,0,3,0" Height="16" Width="16" />
<TextBlock Name="txtBlk" Text="{Binding NodeText}" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在发布问题之前,我实际上找到了解决方案。但我认为这对其他人可能有用。
我向 ScrollViewer 添加了 SizeChanged 处理程序。
在处理程序中,我添加了以下代码。
我很感兴趣是否可以通过绑定 xaml 中的 MaxWidth、MaxHeight 属性来实现这一点。
I found the solution actually before I posted my problem. But I think this might be useful for somebody else.
I added a SizeChanged handler to the ScrollViewer.
At the handler I added the following code.
I would be interested if this can be achieved by binding the MaxWidth, MaxHeight property in xaml.