我正在使用WrapPanel在列中显示可变高度的项目。 wrappanel的大小有限。
有没有办法确定WrapPanel何时“满”?然后我将使用动画页面转到另一个面板。
我已经查看了作为面板子项的项目的ArrangeOverride,但它们似乎总是获得他们想要的所有空间。我需要一种方法来确定它们何时开始被剪裁。
答案 0 :(得分:0)
这是一个使用带有触发器的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。
答案 1 :(得分:0)