【发布时间】:2018-11-13 08:10:52
【问题描述】:
两个小问题,首先为什么我的Polyline 只连接字符串 W、X 和 Y。
其次是可以为多个点解析一个字符串,即:将所有数字存储在字符串 W 中,然后为所有点存储Point.Parse(W)。
private void Button_Click(object sender, RoutedEventArgs e)
{
string W = "0,0";
string X = "99,99";
string Y = " 99, 300";
string Z = "600, 300";
Point[] points = { Point.Parse(W), Point.Parse(X), Point.Parse(Y), Point.Parse (Z)};
DrawLine(points);
}
private void DrawLine(Point[] points)
{
Polyline line = new Polyline();
PointCollection collection = new PointCollection();
foreach (Point p in points)
{
collection.Add(p);
}
line.Points = collection;
line.Stroke = new SolidColorBrush(Colors.Black);
line.StrokeThickness =3;
myGrid.Children.Add(line);
}
【问题讨论】:
-
至于第二个问题:您可以为您的 Point[] 对象选择一个(反)序列化方法。
-
那会是什么样子,我找不到任何适合我情况的好例子。 @PepitoSh
-
任何可以处理对象数组并使用文本作为媒体的序列化方法:xml、json...