我正在使用来自WPF 答案的代码:如何将线条绑定到 UI 元素? 而且我得到“BindingExpression 产生的值对目标属性无效。;值='NaN'”。我的代码和链接中的唯一区别是我不设置Point point = null;
只是Point point;
因为它会产生转换问题。MidpointConcerter.cs 与链接中的完全相同。我的绑定方法:
private void BindLineToScatterViewItems(Line line, ScatterViewItem StartItem, ScatterViewItem EndItem)
{
var x = new MidpointConverter(false);
var y = new MidpointConverter(true);
BindingOperations.SetBinding(line, Line.X1Property,
new Binding { Source = StartItem, Converter = x, ConverterParameter = MidpointSide.Bottom });
BindingOperations.SetBinding(line, Line.Y1Property,
new Binding { Source = StartItem, Converter = y, ConverterParameter = MidpointSide.Bottom });
//old in the middle
BindingOperations.SetBinding(line, Line.X2Property,
new Binding { Source = EndItem, Path = new PropertyPath("ActualCenter.X") });
BindingOperations.SetBinding(line, Line.Y2Property,
new Binding { Source = EndItem, Path = new PropertyPath("ActualCenter.Y") });
}
有人可以帮我说什么是错的,我该如何解决?