有人能解释一下,在WPF(完全属人财产)中使用“拥有者方法”有什么好处吗?我有些误解。
对于斯坦斯,看看下面的代码。
public class TestVisual: Shape
{
private LineGeometry line = new LineGeometry();
public static readonly DependencyProperty XY1Property =
LineGeometry.StartPointProperty.AddOwner(
typeof(TestVisual),
new FrameworkPropertyMetadata(new Point(0,0),
FrameworkPropertyMetadataOptions.AffectsMeasure));
public static readonly DependencyProperty XY2Property =
LineGeometry.EndPointProperty.AddOwner(
typeof(TestVisual),
new FrameworkPropertyMetadata(new Point(0, 0),
FrameworkPropertyMetadataOptions.AffectsMeasure));
public Point XY1
{
get { return (Point)GetValue(XY1Property);}
set { SetValue(XY1Property,value); }
}
public Point XY2
{
get { return (Point)GetValue(XY2Property); }
set { SetValue(XY2Property, value); }
}
protected override Geometry DefiningGeometry
{
get
{
line.StartPoint = XY1 ;
line.EndPoint = XY2;
return line;
}
}
}
从上面的代码中,您可以看到测试视觉类使用 AdPowerer 方法对抚养财产的使用。 好的, 但同样的结果我们可以更容易一些( 我的意思是我们可以得到一个可以调整线线目视觉元素的分类, 设置 XY1 和 XY2 点 ) :
public class TestVisual: Shape
{
private LineGeometry line = new LineGeometry();
public Point XY1
{
get;
set;
}
public Point XY2
{
get;
set;
}
protected override Geometry DefiningGeometry
{
get
{
line.StartPoint = XY1 ;
line.EndPoint = XY2;
return line;
}
}
}
要点是什么?