0

我正在开发交互式图表库......和使用它的应用程序。

在应用程序中, 我有一个ListView带有Points.CurrentItem

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

在同一个面板上,我有两个用于编辑点坐标的文本框:

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

我的大问题是,这Point是一个结构......所以它是按价值传递的。

如果我更改X文本框中的坐标...它不会更改 databind Point

我怎么解决这个问题?
我应该写我自己的Point课,还有Line课,因为她Points是属于PointCollectionPoint吗?

如果需要,我可以发布更多代码:)

谢谢。

4

1 回答 1

1

为什么不创建一个组合控件来更改 Point 而不是Point. 然后您可以绑定到您的Point-property 并且绑定将按预期工作。此外,您可能有一个更好的用户界面。

您可以创建一个UserControl,添加两个文本框并将 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 回答