1

I'm using the code from the answer here WPF: how to bind lines to UI elements? And I'm getting "Value produced by BindingExpression is not valid for target property.; Value='NaN'". The only difference between my code and in the link is that I don't set Point point = null; just Point point; because it produces a convertion problem. The MidpointConcerter.cs is exactyl the same as in the link. My method to bind:

    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") });
        }

Can someone help me and say whats wrong and how I can fix it?

Community
  • 1
  • 1
Judith
  • 51
  • 9
  • Probably best to show us some code here I think, also could you paste the whole binding exception? And you are right to not set Point point = null; since that wouldn't even compile. – Andy Nov 28 '12 at 16:04
  • System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='NaN' BindingExpression:Path=ActualCenter.X; DataItem='ScatterViewItem' (Name='EndItem2'); target element is 'Line' (Name=''); target property is 'X2' (type 'Double') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='NaN' BindingExpression:Path=ActualCenter.Y; DataItem='ScatterViewItem' (Name='EndItem2'); target element is 'Line' (Name=''); target property is 'Y2' (type 'Double') – Judith Nov 28 '12 at 16:07
  • If you break point that method is the parameter line == null? – Andy Nov 28 '12 at 16:11
  • Hmmm, maybe give us some of the XAML so we can see the bindings, in the mean time drink some beer.. that usually helps the diagnosis process. – Andy Nov 28 '12 at 16:20
  • In the MidpointConverter Class the X and Y of point are NaN – Judith Nov 28 '12 at 16:20
  • http://stackoverflow.com/questions/13566293/connecting-scatterviewitems-with-a-line It is the same porject. – Judith Nov 28 '12 at 16:21

1 Answers1

-1

This is because you variable is not initialized. Point point = null is initializing in their code.

Point point; 

merely defines the variable. The only other option you probably have is init it like such

Point point = new Point(); 

Because you cannot bind to an uninitialized variable.

screenshot

enter image description here

Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
  • 1
    Point is a structure and so doesn't need to be initialized with new before it can be used, the values in X and Y are also set to zero to start with not NaN. – Andy Nov 28 '12 at 16:00
  • Hm, what you're saying makes sense, but it doesn't work either. – Judith Nov 28 '12 at 16:00
  • @Andy point does have to be initialized or the compiler complains as you can see in the screenshot I posted above. – Antarr Byrd Nov 28 '12 at 16:07