我有一个带有上下文菜单的列表,当我单击时,选项列表(编辑、删除、信息)将显示在弹出窗口中。
在这里,我需要将这个弹出窗口显示在下面的上下文菜单图标的左侧,因此我需要上下文菜单相对于屏幕的位置。
有没有人能帮我在Xamarin中找到元素的XY位置?
提前感谢!
发布于 2018-08-10 08:17:36
这是我在Xamarin forums中找到的一个方法的版本
public static class ScreenCoords
{
/// <summary>
/// A view's default X- and Y-coordinates are LOCAL with respect to the boundaries of its parent,
/// and NOT with respect to the screen. This method calculates the SCREEN coordinates of a view.
/// The coordinates returned refer to the top left corner of the view.
/// </summary>
public static Point GetScreenCoords(this VisualElement view)
{
Point result = new Point(view.X, view.Y);
var parent = view.Parent as VisualElement;
while (parent != null)
{
result = result.Offset(parent.X, parent.Y);
parent = parent.Parent as VisualElement;
}
return result;
}https://stackoverflow.com/questions/39892518
复制相似问题