我正在尝试基于情节提要滚动我的用户控件(包含列表视图)。但首先要做的事 --- 我需要能够使用情节提要为我的自定义属性设置动画。
我可以为我的自定义属性 ScrollPos 设置动画,但我的 set() 函数根本没有触发。
我怎样才能检测到它已经改变,以便我可以执行实际的滚动?
我的用户控制:
public sealed partial class MyCellListView : UserControl
{
public MyCellListView()
{
this.InitializeComponent();
this.DataContext = this;
}
public const string ScrollPosPropertyTag = "ScrollPos";
public static readonly DependencyProperty ScrollPosProperty =
DependencyProperty.Register(
ScrollPosPropertyTag,
typeof(double),
typeof(MyCellListView),
new PropertyMetadata((double)0));
public double ScrollPos
{
get
{
return (double)GetValue(ScrollPosProperty);
}
set
{
// If I set a breakpoint here, it only gets hit on creation to set
// the initial value of ScrollPos --- not during the storyboard.
SetValue(ScrollPosProperty, value);
}
}
}
它所在的页面:
public MyPage // contains MyCellListView
{
private void startScrolling()
{
// Calculate target offset
double targetOffset = m_teacher.getNumUniqueCues();
// Create animation and storyboard
DoubleAnimation animation = new DoubleAnimation();
ExponentialEase ee = new ExponentialEase();
ee.EasingMode = EasingMode.EaseIn;
ee.Exponent = 3;
animation.EasingFunction = ee;
animation.Duration = new Duration(new TimeSpan(0, 0, 30));
animation.From = 0;
animation.To = targetOffset;
Storyboard.SetTarget(animation, m_listView);
Storyboard.SetTargetProperty(animation,
// Works fine here for "(MyCellListView.Opacity)");
"(MyCellListView.ScrollPos)");
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(animation);
// Need this or the dependent property won't get animated
animation.EnableDependentAnimation = true;
storyboard.Begin();
}
}