I have a problem where my PointCollection won’t bind to the PolyLine. Here is my PolyLine
<Polyline Stroke="Black" StrokeThickness="2" VerticalAlignment="Bottom" Margin="0,0,0,60" Grid.ColumnSpan="5" Height="240" Width="290" Points="{Binding PolyLinePoints}"/>
I want to make a simulation of a graph so that is why I tried Binding. The graph will have 5 points. The X axis is an increment of 75, but the Y axis is what I am trying to bind.
I will now give you a code snippet. I deleted more then half of the function UpdateGraph because it is not relevant to the question. I also added a print statement and I get the values for the X and Y as expected, they just do not want to show in the GUI.
private PointCollection _polylinePoints = new PointCollection();
public PointCollection PolyLinePoints
{
get
{
return _polylinePoints;
}
set
{
_polylinePoints = value;
OnPropertyChanged(nameof(PolyLinePoints));
}
}
private void UpdateGraph()
{
Application.Current.Dispatcher.Invoke(() =>
{
// Clear existing values
_polylinePoints.Clear();
for (int i = 0; i < latestValuesForSelectedEntity.Count; i++)
{
_polylinePoints.Add(new Point(i*75, CalculateYValue(latestValue)));
}
OnPropertyChanged(nameof(PolyLinePoints));
foreach(Point p in _polylinePoints)
{
Debug.WriteLine(p);
}
});
}