임 두 ScatterViewItems에 라인을 결합하려고 :WPF : 두 UiElements의
private void BindLineToScatterViewItems(Shape line, ScatterViewItem origin, ScatterViewItem destination)
{
// Bind line.(X1,Y1) to origin.ActualCenter
BindingOperations.SetBinding(line, Line.X1Property, new Binding { Source = origin, Path = new PropertyPath("ActualCenter.X") });
BindingOperations.SetBinding(line, Line.Y1Property, new Binding { Source = origin, Path = new PropertyPath("ActualCenter.Y") });
// Bind line.(X2,Y2) to destination.ActualCenter
BindingOperations.SetBinding(line, Line.X2Property, new Binding { Source = destination, Path = new PropertyPath("ActualCenter.X") });
BindingOperations.SetBinding(line, Line.Y2Property, new Binding { Source = destination, Path = new PropertyPath("ActualCenter.Y") });
}
하지만 항상 다음과 같은 오류 메시지가 얻을 : 그럼에도 불구하고 그것을
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='NaN' BindingExpression:Path=ActualCenter.X; DataItem='ScatterViewItem' (Name=''); target element is 'Line' (Name=''); target property is 'X1' (type 'Double')
을 작동하지만 어떻게 경고를 무시할 수 있습니까? 그리고이 경고가 표시되는 이유는 무엇입니까?
편집 : 아래의 답변에 따르면, 지금 계산기 다음,하지만 여전히 얻을 사용 오류 :
public class NormalizationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (double) value == double.NaN ? Binding.DoNothing : (double) value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
내가 이러한 경우에 Binding.DoNothing를 사용하는 부분이야 : 그래서 경고를 피하기 위해, 당신은
double.NaN
O
에 변환하는 컨버터를 사용할 수 있습니다. – Goran@ 골란 : 좋은 제안. –
@Goran 어떻게해야합니까? – RoflcoptrException