0

私はインタラクティブなチャートライブラリとそれを使用するアプリケーションを開発しています。

アプリケーションでは、のListViewwithPointsがありCurrentItemます。

public Point CurrentPoint
  {
   get { return myCurrentPoint; }
   set
   {
    myCurrentPoint = value;
    base.OnPropertyChanged("CurrentPoint");
   }
  }

同じパネルに、ポイントの座標を編集するための2つのテキストボックスがあります。

<TextBox Text="{Binding CurrentPoint.X, Mode=TwoWay}" 
       Grid.Column="1" Grid.Row="0" Width="80" Margin="5"/>

私の大きな問題は、それPointが構造であるということです...それでそれは価値によって渡されています。

テキストボックスの座標を変更Xしても...databindは変更されませんPoint

どうすればこの問題を解決できますか?彼女がいるので、
私は自分のPointクラスを書くべきですか、そしてクラスも書くべきですか? LinePointsPointCollectionPoint

必要に応じて、さらにコードを投稿できます:)

ありがとう。

4

1 に答える 1

1

のxコンポーネントとyコンポーネントの代わりに、ポイントを変更する複合コントロールを作成してみませんかPoint。次に、プロパティにバインドでき、バインドPointは期待どおりに機能します。さらに、おそらくより優れたUIがあります。

このコントロールに、を作成しUserControl、2つのテキストボックスを追加して、DependencyProperty-Pointを追加できます。いずれかのテキストボックスの内容が変更されるたびに、Point-propertyを新しい値に設定します。

public class PointInputBox : UserControl{

  public static readonly DependencyProperty PointProperty =
    DependencyProperty.Register("Point", typeof(Point), typeof(PointInputBox), new FrameworkPropertyMetadata(new Point(0,0),FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));


  public Point Point {
    get { return (Point)GetValue(PointProperty); }
    set { SetValue(PointProperty, value); }
  }

  // Add here event handlers for changes of your input boxes and set 
  //  the Point-value accordingly 
于 2011-01-29T11:49:58.260 に答える