Binding of a Polyline. What am I doing wrong?
I am trying what I thought a simple thing: drawing lines of a list of point. If I put the list statically in the xaml of my window everything is ok. If I do the bind, then nothing is displayed.
the window code:
<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
{
    AudioS开发者_JAVA百科ignalModelView 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; }
    }
}
I think the binding is done somehow, because if I put a breakpoint in the getter of the Points property, it is called by the system...
What is obviously wrong in my code ?
You want to bind to the Points property not the DataContext. 
<Polyline Stretch="Fill" Grid.Column="0"
          Name="polyline" Stroke="Red"
          Points="{Binding Points}">  <-- Here
</Polyline>   
MSDN page
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论