开发者

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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜