Im trying to bind a Line to two ScatterViewItems:
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") });
}
But I always get the following error message:
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')
Nevertheless it is working, but how can I surpress this warning? And why is this warning displayed?
EDIT: According to the answer below, I use now following converter, but still get the errors:
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();
}
}