Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 WPF 中的元素之间绘制线条的好方法是什么?
我的应用程序中有一个视图,其中包含组成图表的几个按钮。它们根据视图的大小和形状进行缩放和移动。我想用一条线来表示一些按钮之间的关系。
我没有使用 aCanvas来布置所有内容,因为我希望按钮的相对位置是动态的,并且我不希望所有内容都以相同的速度缩放(就像 aViewBox那样)。
Canvas
ViewBox
您需要创建一个容器控件才能定义按钮的关系。
一旦建立,画线应该是覆盖的问题OnRender,找到每个子控件的位置,并使用DrawingContext来画线。
OnRender
DrawingContext
我的解决方案是在同一个单元格中使用 aGrid和 aCanvas和我的元素。Canvas我在我的代码隐藏文件中画了线。
Grid