Getting the true visual bounding box of a WPF element?

前端 未结 3 1088
醉话见心
醉话见心 2020-12-18 05:53

For a simplified version of my problem, I would like to calculate the bounding box of a layout-transformed (possibly even render-transformed) shape, so that I can always fit

3条回答
  •  甜味超标
    2020-12-18 06:20

    You will get good results with VisualTreeHelper.GetDescendantBounds() and you can use VisualTreeHelper.GetParent() to gain access to the otherwise protected VisualParent property. However what you probably want to do is call GetDescendantBounds on the shape itself, not its parent, because in spite of its name, the method returns the bounds of the parent and all of its decendants.

提交回复
热议问题