Erstellen Sie eine bindbare Punkt in C# WPF

Ich weiß, multiple inheritence ist, aber gibt es eine Möglichkeit zum erstellen eines wrappers für System.Windows.Zeigen Sie, dass Erben von der es aber noch umzusetzen bindbare abhängigkeitseigenschaften?

Ich versuche zu code, so dass für meine XAML kann ich staments wie die folgende ohne Probleme:

<custom:Point X="{Binding Width, ElementName=ParentControlName}" Y="{Binding Height, ElementName=ParentControlName}" />

Wäre es codieren Dinge wie Polygone, Pfade, LineSegments und andere Steuerelemente so viel einfacher.

Den folgenden code als Wunschdenken und ich verstehe, dass es in keiner Weise funktionieren, aber dies ist die Art von Sache, die ich möchte in der Lage sein zu tun:

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 
        { 
            SetValue(XProperty, value);
            base.X = value;
        }
    }

    public new double Y
    {
        get { return (double)GetValue(YProperty); }
        set
        {
            SetValue(YProperty, value);
            base.Y = value;
        }
    }
}

InformationsquelleAutor Ross Graeber | 2011-02-24
Schreibe einen Kommentar