2016-09-21 8 views
-4

PointのXプロパティとYプロパティを別々にバインドしたいと思いますか?
この点がオブジェクトのプロパティであれば、実現可能ですか?
新しいクラスを作成し、暗黙の変換をPointに追加しますか?
(中国語、Googleが翻訳悪い英語、)それは次のように、C#コードで動作xamlのPointのXプロパティとYプロパティを別々にバインドすることはできますか?

<!-- language: lang-c# --> 

public class BindingPoint : Animatable 
{ 
    public double X 
    { 
     get { return (double)GetValue(XProperty); } 
     set { SetValue(XProperty, value); } 
    } 

    // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty XProperty = 
     DependencyProperty.Register("MyProperty", typeof(double), typeof(BindingPoint), new PropertyMetadata(0.0)); 
    public double Y 
    { 
     get { return (double)GetValue(YProperty); } 
     set { SetValue(YProperty, value); } 
    } 

    // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty YProperty = 
     DependencyProperty.Register("MyProperty", typeof(double), typeof(BindingPoint), new PropertyMetadata(0.0)); 

    public BindingPoint() { } 
    public BindingPoint(double x, double y) 
    { 
     X = x; 
     Y = y; 
    } 

    public static implicit operator Point(BindingPoint bp) 
    { 
     return new Point(bp.X, bp.Y); 
    } 
} 

@Trifonこのよう

"点p =新しいBindingPoint(1,1);"? 。
しかしxamlコードでは機能しません!私は、エンドポイントごとに変化する値()にYを結合したい

<Path> 
    <Path.Data> 
     <LineGeometry> 
      <LineGeometry.StartPoint> 
       <!--Type must be "Point"--> 
       <local:BindingPoint X="10" Y="10"/> 
      </LineGeometry.StartPoint> 
     </LineGeometry> 
    </Path.Data> 
</Path> 

@Clemens。
どうすればよいですか?

<Path StrokeThickness="2" Stroke="Cyan" Canvas.Left="300" xmlns:sys="clr-namespace:System;assembly=mscorlib"> 
    <Path.Resources> 
     <sys:Double x:Key="value"/> 
    </Path.Resources> 
    <Path.Data> 
     <GeometryGroup> 
      <LineGeometry StartPoint="50,20"> 
       <LineGeometry.EndPoint> 
        <Point X="30" Y="{StaticResource value}"/> 
       </LineGeometry.EndPoint> 
      </LineGeometry> 
      <LineGeometry StartPoint="50,20"> 
       <LineGeometry.EndPoint> 
        <Point X="50" Y="{StaticResource value}"/> 
       </LineGeometry.EndPoint> 
      </LineGeometry> 
      <LineGeometry StartPoint="50,20"> 
       <LineGeometry.EndPoint> 
        <Point X="70" Y="{StaticResource value}"/> 
       </LineGeometry.EndPoint> 
      </LineGeometry> 
     </GeometryGroup> 
    </Path.Data> 
</Path> 
+0

いいえ。 Pointは依存オブジェクトではありません。 Point.XとPoint.Yは依存関係のプロパティではありません。 –

+0

なぜあなたはそれをしたいですか?ポイントのXとYをバインドする必要があるXAMLを表示します。 – Clemens

+0

'Y =" {StaticResource value} "はバインディングではありません。実際に達成しようとしていることを正確に教えてください。 – Clemens

答えて

0

ポイントをカプセル化する新しいクラスを作成します。新しいクラスXとYのプロパティとして宣言します。次に、新しいクラスのプロパティをバインドできます。

+0

このように?下記参照。 – Flithor

関連する問題