【发布时间】:2012-07-01 02:41:21
【问题描述】:
解决方案 Dynamic Margin on Window Drag
所以我试图让我的多边形随着窗口的移动而移动。我有;
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 清楚地显示了List 中所有Points 的值,并且Polygon 的点肯定在变化。
我还尝试将Polygon 的Points 属性绑定到我的代码。
<Polygon
Name="SpeechPoly"
Points="{Binding myPointCollection, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
Stroke="Black"
StrokeThickness="2"
</Polygon>
我也尝试过使用pointsCollection 而不是List<Points>,但结果相同。几乎看起来Polygon 没有刷新。
【问题讨论】:
标签: c# wpf data-binding polygon point