Getting the top left coordinates of a WPF UIElement

后端 未结 2 694
不知归路
不知归路 2021-01-11 10:44

I am working on extending the Microsoft resize Adorner example and need to be able to reposition the element after say the bottom left drag handle has been drag

2条回答
  •  抹茶落季
    2021-01-11 11:13

    You can transform coordinates of the UIElement to its parent. In your case it's a form. Here is an example of a method that returns coordinates of a visual:

    private Point GetPosition(Visual element) {
       var positionTransform = element.TransformToAncestor(MyForm);
       var areaPosition = positionTransform.Transform(new Point(0, 0));
    
       return areaPosition;
    }
    

提交回复
热议问题