How do you do relative positioning in WPF?

前端 未结 2 451
旧时难觅i
旧时难觅i 2020-12-24 13:18

How can you relatively position elements in WPF? The standard model is to use layout managers for everything, but what if you want to position elements (on a Canvas, for exa

2条回答
  •  余生分开走
    2020-12-24 13:53

    Good question. As far as I know, we need to have a different custom panel to get this feature. Since WPF is based on Visual Hierarchy there is no way to have this sort of Flat structure for the elements in the platform.

    But Here is a trick to do this. Place your elements in the same position and give relative displacement by using RenderTransform.TranslateTransform. This way your TranslateTransfrom's X and Y will always be relatuve to the other element.

提交回复
热议问题