title: Scroller-like animation on a Label in WPF
body: <p>I have a simple app where after clicking a button the value of a label is updated every second.I'm doing this as a POC for a progress bar control that I want to develop.</p>
  
  <p>I would like to know if there is a way to apply some kind of scroller animation to the label which will:</p>
  
  <p>1) When the content of a label is updated it will scroll the new value from the top and the old one will be scrolled down and disappear from view(Hope this makes sence).</p>
  
  <p>I know that this could probably be achieved with some kind of animation but I couldn't find any helpful examples on the web if anyone knows how this can be done please share your expertise:</p>
  
  <p><strong>View:</strong></p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.ScrollerView"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Scroller" DataContext="{StaticResource scrollerVM}" Height="150" Width="300"&gt;
      &lt;Grid&gt;
          &lt;ListBox ItemsSource="{Binding Messages}" Width="200" Height="50" BorderThickness="0" VerticalAlignment="Top" HorizontalAlignment="Left"&gt;
              &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Label Content="{Binding Text}"  /&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ItemsControl.ItemTemplate&gt;
          &lt;/ListBox&gt;
          &lt;Button Width="70" Height="24" Content="Add new" Command="{Binding AddNew}" HorizontalAlignment="Left" Margin="0,56,0,30" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>View model:</strong></p>
  
  <pre><code>using System;
  using System.Collections.ObjectModel;
  using System.ComponentModel;
  using System.Windows.Threading;
  
  namespace WpfApplication1.Scroller
  {
      public class Message
      {
          public Message(string _text)
          {
              text = _text;
          }
  
          private string text;
          public string Text
          {
              get { return text; }
              set {text = value;}
          }
      }
  
      public class ScrollerViewModel : INotifyPropertyChanged
      {
          public event PropertyChangedEventHandler PropertyChanged;
          public DelegateCommand AddNew { get; protected set; }
  
          ObservableCollection&lt;Message&gt; _messages = new ObservableCollection&lt;Message&gt;();
          public ObservableCollection&lt;Message&gt; Messages
          {
              get { return _messages; }
              set
              {
                  _messages = value;
                  OnPropertyChanged("Messages");
              }
          }
  
          public ScrollerViewModel()
          {
              AddNew = new DelegateCommand(Add);
          }
  
          private void Add(object parameter)
          {
              DispatcherTimer timer = new DispatcherTimer();
              timer.Tick += new System.EventHandler(timer_Tick);
              timer.Interval = new System.TimeSpan(0, 0, 1);
              timer.Start();
          }
  
          private void timer_Tick(object sender, EventArgs e)
          {
              Messages.Clear();
              Messages.Add(new Message(DateTime.Now.ToString("ss")));
          }
  
          protected void OnPropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
              {
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
              }
          }
      }
  }
  </code></pre>