我有一个这样定义的示例依赖属性:
public Polyline Shape
{
get { return (Polyline)GetValue(ShapeProperty); }
set { SetValue(ShapeProperty, value); }
}
public static readonly DependencyProperty ShapeProperty =
DependencyProperty.Register("Shape", typeof(Polyline),
typeof(CustomControl), new FrameworkPropertyMetadata(null,
FrameworkPropertyMetadataOptions.AffectsRender, onShapeAdded));
我是这样设置的:
<local:CustomControl>
<local:CustomControl.Shape>
<Polyline Points="0,180 0,80 70,80 90,180 0,180" />
</local:CustomControl.Shape>
</local:CustomControl>
它的回调看起来像这样:
private static void onShapeAdded(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
Polyline control = (Polyline)e.NewValue;
//control.Points is always null
}
为什么在回调期间积分集合总是为空?(每个属性都会发生这种情况)最后点已设置,所以我想我太快访问我的控件,但是我应该何时以及如何访问设置了所有属性的控件?