Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an example where I created a wrapper control called AnimatableScrollViewer, which holds a usual ScrollViewer and a TextBlock.</p> <pre><code>&lt;UserControl&gt; &lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt; &lt;ScrollViewer x:Name="scrollViewer" Width="{Binding ActualWidth, ElementName=userControl, Mode=OneWay}" Height="{Binding ActualHeight, ElementName=userControl, Mode=OneWay}"&gt; &lt;TextBlock TextWrapping="Wrap" Text="Add some pretty long text here..."/&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>In the code-behind, I added a DependencyProperty (which we can animate from outside) that calls the ScrollToVerticalOffset() method of our ScrollViewer at every change.</p> <pre><code>public partial class AnimatableScrollViewer : UserControl { public static readonly DependencyProperty AnimatablOffsetProperty = DependencyProperty.Register("AnimatableOffset", typeof(double), typeof(AnimatableScrollViewer), new PropertyMetadata(AnimatableOffsetPropertyChanged)); public double AnimatableOffset { get { return (double)this.GetValue(AnimatablOffsetProperty); } set { this.SetValue(AnimatablOffsetProperty, value); } } public AnimatableScrollViewer() { InitializeComponent(); AnimatableOffset = scrollViewer.VerticalOffset; } private static void AnimatableOffsetPropertyChanged(object sender, DependencyPropertyChangedEventArgs args) { AnimatableScrollViewer cThis = sender as AnimatableScrollViewer; cThis.scrollViewer.ScrollToVerticalOffset((double)args.NewValue); } } </code></pre> <p>Now you can add the AnimatableScrollViewer to a PhonePage and animate it. For example in a button eventhandler like this one:</p> <pre><code>private void cmdScroll_Click(object sender, RoutedEventArgs e) { // Calculate target offset double targetOffset = 1000; // Create animation and storyboard DoubleAnimation animation = new DoubleAnimation(); animation.EasingFunction = new CircleEase(); animation.Duration = new Duration(new TimeSpan(0, 0, 2)); animation.From = animatableScrollViewer.AnimatableOffset; animation.To = targetOffset; Storyboard.SetTarget(animation, animatableScrollViewer); Storyboard.SetTargetProperty(animation, new PropertyPath("(AnimatableScrollViewer.AnimatableOffset)")); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(animation); storyboard.Begin(); } </code></pre> <p>Of course you can also create the animation in your xaml code which would make it look a litte cleaner. Right now, the content of the ScrollViewer is fixed... you can make it changeable by adding more dependency properties to the wrapper class.</p> <p>I don't know if this is the best solution, in fact it looks quite ugly to me but it should give you an idea of how it can be done.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload