WPF: ListView height animation when end height is unknown

I have a ListView that is very simply defined in my XAML so

<ListView Name="myListVew" MaxHeight="200" Visibility="Collapsed">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Line" Width="Auto" DisplayMemberBinding="{Binding Line}" />
            <GridViewColumn Header="Error" Width="Auto" DisplayMemberBinding="{Binding Error}" />
        </GridView>
    </ListView.View>
</ListView>

When I want the ListView to appear, I want to animate the height of the list from 0. The problem is that I don’t know the final height of the ListView, because it will depend on how many elements are displayed inside This. Is there any way to do this?

+3
source share
2 answers

You do not hate it when you are looking for a watch to solve, post a question on the forum, and then find the answer yourself in 10 minutes?

Anyway, I got it working by applying layout scale transform, for example:

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ErrorDisplay" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
    <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
    <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
+5
source

, - .

Auto, , .

:

<Border Name="ContainerBorder">
  <!-- Stuff... -->
</Border>

:

<Storyboard x:Key="EditIn">
  <DoubleAnimation Storyboard.TargetProperty="Height"
                   Storyboard.TargetName="ContainerBorder"
                   Name="BorderAnimation"
                   To="45"
                   Duration="0:0:0.8" />
</Storyboard>

, , codebehind:

private void Edit_Click(object sender, RoutedEventArgs e) {
  Storyboard sb = (Storyboard)FindResource("EditIn");
  //Find the border animation
  DoubleAnimation da = (DoubleAnimation)sb.Children.Where(t => t.Name == "BorderAnimation").FirstOrDefault();
  if (da != null) { da.From = ContainerBorder.ActualHeight; }
  sb.Begin(this);
}

, "From" FrameworkElement ActualHeight.

+1

Source: https://habr.com/ru/post/1707379/


All Articles