自定义依赖属性
public class MyCanvas : Canvas
{
/// <summary>
/// 获取或设置身体图片
/// </summary>
public double TestWidth
{
get { return (double)GetValue(TestWidthProperty); }
set { SetValue(TestWidthProperty, value); }
}
public static readonly DependencyProperty TestWidthProperty = DependencyProperty.Register(
"TestWidth",
typeof(double),
typeof(MyCanvas),
new PropertyMetadata(0, new PropertyChangedCallback(ChangeTestWidthProperty))
);
public static void ChangeTestWidthProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MyCanvas objectBase = d as MyCanvas;
objectBase.Width = (double)e.NewValue;
}
}
动画调用
DoubleAnimation animation = new DoubleAnimation() { From = 100, To = 300 };
animation.EnableDependentAnimation = true;
Storyboard.SetTarget(animation, img);
Storyboard.SetTargetProperty(animation, "TestWidth");
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin();
但是报错,望有知道的人解答,难道自定属性win8 app不支持动画?
还真没看出错在那1
targetname 呢