我知道多个继承已经出来了,但有没有办法为System.Windows.Point创建一个包装器,它可以继承它但仍然实现可绑定的依赖属性?
我正在尝试编码,以便我的XAML可以创建如下的staments而不会出现问题:
<custom:Point X="{Binding Width, ElementName=ParentControlName}" Y="{Binding Height, ElementName=ParentControlName}" />
它可以使像Polygons,Paths,LineSegments和其他控件这样的编码变得更加容易.
以下代码是作为一厢情愿的想法提供的,我理解它不会起作用,但这是我希望能够做到的事情:
public class BindablePoint: DependencyObject, Point
{
public static readonly DependencyProperty XProperty =
DependencyProperty.Register("X", typeof(double), typeof(BindablePoint),
new FrameworkPropertyMetadata(default(double), (sender, e) =>
{
BindablePoint point = sender as BindablePoint;
point.X = (double) e.NewValue;
}));
public static readonly DependencyProperty YProperty =
DependencyProperty.Register("Y", typeof(double), typeof(BindablePoint),
new FrameworkPropertyMetadata(default(double), (sender, e) =>
{
BindablePoint point = sender as BindablePoint;
point.Y = (double)e.NewValue;
}));
public new double X
{
get { return (double)GetValue(XProperty); }
set …Run Code Online (Sandbox Code Playgroud) 如果我有一条封闭的路径,我可以Geometry.GetArea()用来近似我的形状区域.这很棒,节省了我很多时间.但周围有什么可以帮助我找到一条未封闭路径的长度吗?
我现在能够想出的最好PathGeometry的GetPointAtFractionLength方法是确保我正在使用并多次调用该方法,获得积分并累加所有这些点之间的距离.
码:
public double LengthOfPathGeometry(PathGeometry path, double steps)
{
Point pointOnPath;
Point previousPointOnPath;
Point tangent;
double length = 0;
path.GetPointAtFractionLength(0, out previousPointOnPath, out tangent);
for (double progress = (1 / steps); progress < 1; progress += (1 / steps))
{
path.GetPointAtFractionLength(progress, out pointOnPath, out tangent);
length += Distance(previousPointOnPath, pointOnPath);
previousPointOnPath = pointOnPath;
}
path.GetPointAtFractionLength(1, out pointOnPath, out tangent);
length += Distance(previousPointOnPath, pointOnPath);
return length;
}
public static double Distance(Point p0, Point p1)
{ …Run Code Online (Sandbox Code Playgroud)