ScrollViewer 动画滚动效果,请大侠帮忙

kingdomxmk 2011-06-02 02:15:00
DoubleAnimation doubleAnimation = new DoubleAnimation();//创建双精度动画对象

doubleAnimation.To = scrollViewer1.VerticalOffset + downY - upY;//设置动画的结束值
doubleAnimation.Duration = TimeSpan.FromSeconds(1.5);//设置动画时间线长度
doubleAnimation.AccelerationRatio = 0.5;//动画加速
doubleAnimation.DecelerationRatio = 0.5;//动画减速
doubleAnimation.FillBehavior = FillBehavior.HoldEnd;//设置动画完成后执行的操作
scrollViewer1.BeginAnimation(ScrollViewer.VerticalOffsetProperty, doubleAnimation);

运行到最后一句提示错误:
“VerticalOffset”属性在“System.Windows.Controls.ScrollViewer”类上不是可动态的,因为 UIPropertyMetadata 上已设置 IsAnimationProhibited 标记,用于将属性与类关联。
参数名: dp

不知道有没有其他好的解决方法
...全文
361 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjl19911105 2012-05-28
  • 打赏
  • 举报
回复
5楼的帅锅,给我也来一份 谢谢了,,877534719qq.com
wongeo 2012-05-11
  • 打赏
  • 举报
回复
也发给我一份吧 29992379@qq.com 先谢谢了[Quote=引用 5 楼 的回复:]

或者,如果你非要用Storyboard来实现ScrollViewer的动画滚动,你可以设计一个Attached Property来实现,不过这个代码写起来有些麻烦,不是在论坛上说几句就可以的,过几天我给出解决方案
[/Quote]
cacaca6 2011-08-19
  • 打赏
  • 举报
回复
或者,如果你非要用Storyboard来实现ScrollViewer的动画滚动,你可以设计一个Attached Property来实现,不过这个代码写起来有些麻烦,不是在论坛上说几句就可以的,过几天我给出解决方案
cacaca6 2011-08-19
  • 打赏
  • 举报
回复
其中一个解决方法是用 DispatcherTimer 来做,sample 代码如下:


DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(0.2);
int counter = 0;
timer.Tick += (s, ee) =>
{
if (counter == 200) timer.Stop();
counter++;
ScrollViewer.ScrollToHorizontalOffset(counter);
};
timer.Start();
cacaca6 2011-08-19
  • 打赏
  • 举报
回复

ScrollViewer.VerticalOffset 是一个Getter,没有Setter,所以你不能给它赋值,你只能用
ScrollViewer.ScrollToHorizontalOffset(double value)来达到相同效果
花心达萝卜 2011-08-15
  • 打赏
  • 举报
回复
你们是怎么解决的啊
crz7789 2011-06-08
  • 打赏
  • 举报
回复
遇到同样的问题,帮顶下

8,734

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧