Hello Walter,
I have some links and nodes getting drawn automatically in my diagram. Those links have a template, which contains a StackPanel with two TextBlocks. The links can be drawn either horizontally or diagonal. If drawn horizontally both TextBlocks need to be displayed above the link, otherwise one above and one below.
So in case of horizontal:
<StackPanel go:LinkPanel.Alignment="MiddleBottom"> ... </StackPanel>
And in case of diagonal:
<StackPanel go:LinkPanel.Alignment="Center"> ... </StackPanel>
Now in order to achieve this distinction, I’ve written a converter and bound the StackPanel to Link, which ultimately contains the from and to nodes to compare their Location.X values.
<StackPanel go:LinkPanel.Alignment="{Binding Path=Link, Converter={StaticResource ResourceKey=PartToAlignmentConverter}}"> ... </StackPanel>
And the converter function:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((value as Link) != null && ((Link)value).FromNode.Location.X == ((Link)value).ToNode.Location.X)
{
return ...
}
return ...
}
Now the question is, what does the converter actually need to return for it to work? Returning string “Center” and “MiddleBottom” does not work and neither does returning new Spot(0.5, 1)
and new Spot(0.5, 0.5)
. The documentation only says Alignment
is of type DependencyProperty
, which is no help at all.