简体   繁体   English

WPF在Canvas布局上的锚定/停靠行为

[英]Anchoring/docking behavior in WPF on Canvas layout

I am arranging quite freely a lot of elements on a Canvas layout, in fact the elements represent an interactive flow-chart. 我在Canvas布局上自由地安排了许多元素,实际上,这些元素代表了交互式流程图。 As transformations are applied, I need relative transformations on some of the elements. 应用转换时,我需要对某些元素进行相对转换。

Especially I require some elements being anchored or docked to their parent elements. 特别是我需要将某些元素锚定或停靠在其父元素上。 I found different solutions, however I don't know if they solve my problem in the most elegant way. 我找到了不同的解决方案,但是我不知道它们是否以最优雅的方式解决了我的问题。

Here is an example: 这是一个例子:

<Line X1="80" X2="800" Y1="730" Y2="730"/>
<Polygon Points="0,30 40,0 40,60" Canvas.Left="48" Canvas.Top="700"/>

The Polygon draws a triangle and I would like to let it dock on the left side of line. 多边形绘制一个三角形,我想让它停靠在线条的左侧。 Which means, when translating the line to a new position or when scaling it down, the Polygon should move with it. 这意味着,将线平移到新位置或按比例缩小时,多边形应随之移动。

Is this possible? 这可能吗?

put them in a canvas of their own, that way you can position the outer canvas absolutely and keep the inner stuff together. 将它们放在自己的画布中,这样您就可以绝对定位外部画布并将内部的东西放在一起。

like this: 像这样:

<Canvas>
    <Line X1="60" X2="820" Y1="60" Y2="760"> <!--some other line--> </Line>
    <Canvas Canvas.Left="48" Canvas.Top="700">
        <Polygon Points="0,30 40,0 40,60"/>
        <Line X1="32" X2="752" Y1="30" Y2="30"/>
    </Canvas>        
</Canvas>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM