SOLUTION
Dynamic Margin on Window Drag
So I’m trying to get my polygon to move as the window is moved. I have;
private void ResetPolygon(Point Point1, Point Point2, Point Point3)
{
SpeechPoly.Points.Clear();
ObservableCollection<Point> myPointCollection = new ObservableCollection<Point>();
myPointCollection.Add(Point3);
myPointCollection.Add(Point2);
myPointCollection.Add(Point1);
foreach (Point p in myPointCollection)
{
SpeechPoly.Points.Add(p);
}
}
private void Window_LocationChanged(object sender, EventArgs e)
{
if (this.IsLoaded)
{
Point Point1 = new Point(newPoint3);
Point Point2 = new Point(newPoint2);
Point Point3 = new Point(newPoint1);
ResetPolygon(newPoint1, newPoint2, newPoint3);
//Write out the values of both the list and the polygon to screen!
txtBlock.Text = newPoint1.X.ToString("N2") + ", " + newPoint1.Y.ToString("N2") +
"\n" + newPoint2.X.ToString("N2") + ", " + newPoint2.Y.ToString("N2") + "\n" +
newPoint3.X.ToString("N2") + ", " + newPoint3.Y.ToString("N2");
txtBlock.Text += "\n" + SpeechPoly.Points[0].X.ToString("N2") + ", " +
SpeechPoly.Points[0].Y.ToString("N2") + "\n" + SpeechPoly.Points[1].X.ToString("N2") + ", " +
SpeechPoly.Points[1].Y.ToString("N2") + "\n" + SpeechPoly.Points[2].X.ToString("N2") + ", "+
SpeechPoly.Points[2].Y.ToString("N2");
}
}
But the Polygon remains the same shape no matter what, even though the Textblock clearly shows the values of all the Points in the List and the Polygon‘s points are definitely changing.
I’ve also tried to bind the Points property of the Polygon to my code.
<Polygon
Name="SpeechPoly"
Points="{Binding myPointCollection, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
Stroke="Black"
StrokeThickness="2"
</Polygon>
I’ve also tried using a pointsCollection as opposed List<Points> but same result. Almost seems like the Polygon is not refreshing.
I was not being satisfied with the previous answer I gave as it is after all a workaround..
I found a better solution to the problem which will not require to reset the databinds.
So the binding from XAML is being directed to a property with INCC however the data itself is converted to Points for the polygon to use when drawing.