views:

732

answers:

2

I'm using a WrapPanel to display variable height items in columns. The wrappanel has a constrained size.

Is there an way to determine when the WrapPanel is 'full'? I will then page to another panel with an animation.

I've looked at the ArrangeOverride of the items that are the panels children, but they always seem to be getting all the space they want. I need a way to determine when they begin getting clipped.

A: 

Here's an example using a ScrollViewer with a trigger to determine whether it would display using ScrollableHeight. Right now it just changes some text but you could do other things. Removing one of the Rectangles will fire the trigger:

<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>

You could also trigger based on ScrollViewer.ComputedVerticalScrollBarVisibility, but that requires the ScrollBar to actually be visible, whereas when you trigger based on ScrollableHeight, the ScrollBar can be hidden.

Robert Macnee
A: 

Actually using a WrapPanel for what you are trying to achieve doesn't seem like a good idea.

"[...] I will then page to another panel with an animation."

This would be layout to layout animation what isn't to easy, too.

You should write your own panel class: see here or (animated) here

Hades32