解决方案 窗口拖动时的动态边距
所以我试图让我的多边形随着窗口的移动而移动。我有;
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");
}
}
但是多边形无论如何都保持相同的形状,即使Textblock
清楚地显示了所有点的值Points
和List
点Polygon
肯定在变化。
我还尝试将 的Points
属性绑定Polygon
到我的代码。
<Polygon
Name="SpeechPoly"
Points="{Binding myPointCollection, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
Stroke="Black"
StrokeThickness="2"
</Polygon>
我也尝试过使用pointsCollection
相反List<Points>
但相同的结果。几乎看起来Polygon
并不令人耳目一新。