I have two custom controls that are analogous to a node and the control that draws links between nodes.
I would like to have both controls written as much in xaml as possible. The link stores both nodes as dependency properties, and I use databinding to move the line between the nodes whenever the nodes move.
It would be great to be able to change some other value of the line, for instance the stroke width, depending on the distance between the two nodes. So the property needs to update when either node moves, and I can’t quite get my head around how that would work.
Anyone got any ideas?
you can try doing something like that:
Implement interface IMultiValueConverter, which will basically calculate how the stroke should look like based on the distance between nodes.
in xaml create instance of your converter, and add it to your multibinding’s Converter property.
the advantage of this solution is, that you have pretty clear class model and each class does simple tasks. moreover, later on, you can configure your converter class to support extra cases without touching node class which stays simple and is designed simply for displaying nodes.
in general, whenever you have to map multiple property values to one other property, you’ll have to use multibinding and converter.