Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 210211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:59:06+00:00 2026-05-11T17:59:06+00:00

I have a ListView that is set up with a MinHeight and a MaxHeight.

  • 0

I have a ListView that is set up with a MinHeight and a MaxHeight. The final height is determined by the number of items inside the list.

At the moment, when a list is added to the ItemsSource property of the ListView, the height jumps to the final height. Is there a way to animate this change in height, so that it’s smooth?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:59:06+00:00Added an answer on May 11, 2026 at 5:59 pm

    Here’s an example of something that does what you want (as I understand it). I’ll call this “quick and dirty” and don’t claim to have put a whole lot of thought into it.

        public class CustomListView : ListView
        {
            public bool IsAttached
            {
                get { return (bool)GetValue(IsAttachedProperty); }
                set { SetValue(IsAttachedProperty, value); }
            }
    
            // Using a DependencyProperty as the backing store for IsAttached.  
            // This enables animation, styling, binding, etc...
            public static readonly DependencyProperty IsAttachedProperty =
                DependencyProperty.Register("IsAttached", 
                    typeof(bool), 
                    typeof(CustomListView), 
                    new UIPropertyMetadata(false));
        }
    
        public class ViewModel : INotifyPropertyChanged
        {
            public void PopulateItems()
            {
                Items = new List<string>();
    
                for (var i = 0; i < 200; i++ )
                {
                    Items.Add("The quick brown fox jumps over the lazy dog.");
                }
                InvokePropertyChanged(new PropertyChangedEventArgs("Items"));
    
                IsAttached = true;
                InvokePropertyChanged(new PropertyChangedEventArgs("IsAttached"));
            }
    
            public List<string> Items { get; private set; }
            public bool IsAttached { get; private set; }
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            private void InvokePropertyChanged(PropertyChangedEventArgs e)
            {
                var changed = PropertyChanged;
    
                if (changed != null)
                {
                    changed(this, e);
                }
            }
        }
    
    <Window x:Class="AnimateHeight.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:AnimateHeight"
        Title="Window1" Height="300" Width="300">
        <StackPanel>
            <Button Width="100" Content="Add Items" Click="OnClickAddItems"/>
            <local:CustomListView x:Name="VariableListView" ItemsSource="{Binding Items}" IsAttached="{Binding IsAttached}" >
                <local:CustomListView.Style>
                    <Style TargetType="{x:Type local:CustomListView}">
                        <Setter Property="MinHeight" Value="50" />
                        <Setter Property="MaxHeight" Value="50" />
                        <Style.Triggers>
                            <Trigger Property="IsAttached" Value="true">
                                <Trigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation 
                                                Storyboard.TargetProperty="(ListView.MaxHeight)" 
                                                To="150" 
                                                Duration="0:0:5"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </Trigger.EnterActions>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </local:CustomListView.Style>
            </local:CustomListView>
        </StackPanel>
    </Window>
    
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
    
                DataContext = new ViewModel();
            }
    
            private void OnClickAddItems(object sender, RoutedEventArgs e)
            {
                ((ViewModel)DataContext).PopulateItems();
            }
        }
    

    UPDATE: You should be able to copy this into .cs and .xaml files and run it as an example application. To summarize what I’m doing: Set the MaxHeight property to something artificially low, in my case I just set it to the same value as the MinHeight. Then you can create a storyboard that animates the MaxHeight to its real value, which gives you the smooth transition effect. The trick is indicating when to start the animation, I use a dependency property in a subclassed ListView just because that seemed to be the easiest option to implement in a hurry. I just have to bind the dependency property to a value in my ViewModel and I can trigger the animation by changing that value (since I don’t know of an easy way to trigger an animation based on a change to a ListView ItemsSource off the top of my head).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that I set it's ItemsSource to list all the Assignments
I have a ListView on a page that displays a list of widgets. When
I have a ListView that has some minor visual preferences that are set in
A have a ListView that is rendered with multiple items. Now I want to
I have a listView that lists a bunch of files, and a set of
I have a listview that needs to be multiple choice (i.e each list item
I have a listview that is binded to a ThreadSafeObservableCollection. The background of each
I have a WPF ListView that is bound to a BindingList<T>. The binding works
I have a ListView control that is in FullRowSelect mode, MultiSelect off and using
I have a ListView in WPF that is databound to a basic table that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.