我正在尝试我认为的一件简单的事情:绘制点列表的线条。如果我将列表静态地放在窗口的 xaml 中,一切正常。如果我进行绑定,则不会显示任何内容。
窗口代码:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Polyline Stretch="Fill" Grid.Column="0" Name="polyline" Stroke="Red" DataContext="{Binding Points}">
</Polyline>
</Grid>
public partial class testWindow2 : Window
{
AudioSignalModelView audioSignalModelView;
public testWindow2()
{
InitializeComponent();
audioSignalModelView = new AudioSignalModelView();
this.DataContext = audioSignalModelView;
}
}
public class AudioSignalModelView
{
public AudioSignalModelView()
{
Point pointA = new Point {X=0,Y=0};
Point pointB = new Point { X = 0.2, Y = 0.4 };
Point pointC = new Point { X = 0.8, Y = 0.1 };
Point pointD = new Point { X = 1, Y = 1 };
Points.Add(pointA);
Points.Add(pointB);
Points.Add(pointC);
Points.Add(pointD);
}
private AudioSignalTest audioSignalTest;
private PointCollection _points = new PointCollection();
public PointCollection Points
{
get { return _points; }
}
}
我认为绑定是以某种方式完成的,因为如果我在 Points 属性的 getter 中放置一个断点,它就会被系统调用......
我的代码明显有什么问题?