Search code examples
wpfsilverlightstackpanel

Connect StackPanels and Border with a line


I have my own control which derives from StackPanel. This control contains two other controls, first Border (with TextBlock inside) and StackPanel (able to containes other StackPanels).
Now, when I new StackPanel is added to the internal StackPanel I would like to draw a Line which could connect Border with a new added StackPanel.
I guess this can be handle in code, so when I need StackPanel is added I could determine his and Border locations, and base on this I could draw a line. So my question is: can you see any other ways to achieve the same result? how can keep the link between Border and StackPanel when one of the items it is dragging the layout ? Thank you for your help BR Jarek


Solution

  • You can do this the super-easy way by doing something like this:

    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel>
            <Border Margin="10 0 0 0" BorderBrush="Black" BorderThickness="5 0 0 0" >
                <TextBlock Text="MyText" Margin="5 0 0 0 " />
            </Border>
            <StackPanel Margin="10 0 0 0" Orientation="Vertical">
                <Border  BorderBrush="Black" BorderThickness="5 0 0 0">
                    <TextBlock Text="Sub-Item 1" Margin="15 0 0 0" />
                </Border>
                <Border  BorderBrush="Pink" BorderThickness="5 0 0 0">
                    <TextBlock Text="Sub-Item 2" Margin="15 0 0 0" />
                </Border>
                <Border  BorderBrush="Black" BorderThickness="5 0 0 0">
                    <TextBlock Text="Sub-Item 3" Margin="25 0 0 0" />
                </Border>
            </StackPanel>
        </StackPanel>
    </Grid>