I use this method to bind a Line to the center of 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 now I'd like to bind it from the bottom from one ScatterViewItem to the top of the another ScatterViewItem:
How can I achieve that?
You could:
Use a
IValueConverter
that takes the bounding rectangle of the view item and a converter parameter to specify the side to calculate the center from.The converter you would use would be:
Keep the same
ActualCenter
bindings, but make theZIndex
of the line below that of the rectangles. Using this approach will likely keep you from having to detect if oneScatterViewItem
moves in such a way that needs to change the side used in the converter.is there a reason this wouldnt work to set the converter?