将List <point>添加到C#中的变量?

时间:2018-03-15 17:40:20

标签: c# list silverlight collections point

我有一个转换方法,它接收public int method(int column) { int result = Integer.MIN_VALUE; for(int x = 0; x<array[column].length; x++) { result = Math.max(result, array[column][x]); } return result; } 。该值使用数组填充:

points in <code>value</code>

但是当我尝试将object value存储在名为value as List<Point>的变量中时,point会保留point

null

如何将public class PointsToPointsCollectionsConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var points = value as List<Point>; if (points != null) { var pc = new PointCollection(); foreach (var point in points) { pc.Add(point); } return pc; } else return null; } } 分配给变量value as <List>

由于

1 个答案:

答案 0 :(得分:1)

如果您仔细查看屏幕截图,您会发现value变量不是点数组,而是System.Windows.Media.PointCollection。如果您要查看PointCollection类的documentation,您会发现它没有实现List<Point>,因此您尝试执行类型转换为List<Point>是按预期评估为null

您应该将类​​型转换更改为PointCollection实际实现的类型。看到你正在做的就是迭代集合来复制它,IEnumerable<Point>将是最合适的选择:

var points = value as IEnumerable<Point>;
相关问题