我有一个转换方法,它接收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;
}
。该值使用数组填充:
但是当我尝试将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>
?
由于
答案 0 :(得分:1)
如果您仔细查看屏幕截图,您会发现value
变量不是点数组,而是System.Windows.Media.PointCollection
。如果您要查看PointCollection
类的documentation,您会发现它没有实现List<Point>
,因此您尝试执行类型转换为List<Point>
是按预期评估为null
。
您应该将类型转换更改为PointCollection
实际实现的类型。看到你正在做的就是迭代集合来复制它,IEnumerable<Point>
将是最合适的选择:
var points = value as IEnumerable<Point>;