我正在使用 WrapPanel 在列中显示可变高度项。包裹面板的大小受到限制。
有没有办法确定 WrapPanel 何时“满”?然后,我将使用动画分页到另一个面板。
我已经查看了作为子面板的项目的 ArrangeOverride,但它们似乎总是获得他们想要的所有空间。我需要一种方法来确定它们何时开始被剪裁。
这是一个使用带有触发器的 ScrollViewer 来确定它是否会使用ScrollableHeight显示的示例。现在它只是改变了一些文本,但你可以做其他事情。删除其中一个矩形将触发触发器:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="100" Height="50">
<ScrollViewer x:Name="scrollViewer" VerticalScrollBarVisibility="Hidden">
<WrapPanel>
<Rectangle Width="50" Height="20" Fill="Red"/>
<Rectangle Width="50" Height="20" Fill="Blue"/>
<Rectangle Width="50" Height="20" Fill="Green"/>
<Rectangle Width="50" Height="20" Fill="Yellow"/>
<Rectangle Width="50" Height="20" Fill="Orange"/>
</WrapPanel>
</ScrollViewer>
<TextBlock IsHitTestVisible="False">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Text" Value="Clipped"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=scrollViewer, Path=ScrollableHeight}" Value="0">
<Setter Property="Text" Value="Not Clipped"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
您也可以基于ScrollViewer.ComputedVerticalScrollBarVisibility触发,但这需要 ScrollBar 实际可见,而当您基于ScrollableHeight触发时,可以隐藏 ScrollBar。