我在我的应用程序中使用滚动查看器,它以水平视图显示图像。我需要在滚动时使用动画,就像在这个视频中一样如何实现这一点
http://www.youtube.com/watch?v=XVHVBMeqL24
我试过这个
public Storyboard CreateAndApplyStoryboard(UIElement targetElement)
{
Storyboard sb = new Storyboard();
DoubleAnimation animation =
new DoubleAnimation { From = 0, To = 500, Duration = new Duration(TimeSpan.FromSeconds(1.0)) };
//ExponentialEase ese = new ExponentialEase();
//ese.EasingMode = EasingMode.EaseIn;
//animation.EasingFunction = ese;
Storyboard.SetTarget(animation, targetElement);
Storyboard.SetTargetProperty(animation,
new PropertyPath(ScrollViewer.HorizontalOffsetProperty));
sb.Children.Add(animation);
return sb;
}
我只是展示我需要从水平偏移量 0 滚动到 500 的示例
如何使用依赖属性?
<scrollviewer name="scroll">
<StackPanel Name="stack" Width="5000" Orientation="Horizontal" HorizontalAlignment="Left" >
<StackPanel.RenderTransform>
<TranslateTransform x:Name="Trans2" X="0" Y="0" />
</StackPanel.RenderTransform>
</StackPanel>
private void button1_Click(object sender, RoutedEventArgs e)
{
Storyboard sb = CreateAndApplyStoryboard(scroll);
sb.Begin();
}