Converter for alignment property

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.

The documentation for that is here: SetAlignment Method (LinkPanel)
In general for attached dependency properties, you need to look at the static methods for getting and setting the property value.

I’m not sure the converter function will be called at the desired times. You’ll need to debug that or insert trace messages to determine when it is called.

I just realized, returning Spot didn’t work because I compared X instead of Y, it works now. You should include that information in your documentation, as this might come in very handy to know.