How to get the child elements of a Absolute layout based on X,Y coordinates?

I am working to find the child element of an absolute layout based on the bounds of that child. There is an absolute layout which contains a label, I wan to find the child elements based on a set of coordinates. I can get the bounds of the label but when I try to use the bounds as a point in "GetChildElements" method, I am getting an error. It can be seen in the first attached screenshot that the I can get the bounds of a label but cannot use them a point. Can someone please check the code below and let me know what am I doing wrong? The error comes up when I run the last line of the code and use
GetChildElements() method.


<?xml version="1.0" encoding="utf-8" ?>![]( "")

<ContentPage xmlns=""
             xmlns:x=""![]( "")

        <!--Container Absolute Layout Padding="50" -->
        <AbsoluteLayout x:Name="absContainer">
            <!--Header  Label Style="{StaticResource headerStyle}" -->
            <Label x:Name="hdrLbl" Text="Arrange Page1 =>" AbsoluteLayout.LayoutBounds=".1,5,.4,80" AbsoluteLayout.LayoutFlags="XProportional,WidthProportional"></Label>
            <!-- Absolute Layout Structure Description in Middle  BackgroundColor="LightPink"       -->
            <AbsoluteLayout x:Name="absTopic" AbsoluteLayout.LayoutBounds=".1,.3,.5,.5" AbsoluteLayout.LayoutFlags="All">
                <Label x:Name="lblNew1" Text="First label" AbsoluteLayout.LayoutBounds="30, 30, 80, 50" BackgroundColor="LightSalmon"></Label>
                <!--<Label x:Name="lblNew2" Text="Second label"></Label>-->

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace TouchTrackingEffect
    public partial class PageElementPoint : ContentPage
        public PageElementPoint()
            // checking the child element at a point
            // finding the child elements of the absTopic at a Point
            Rectangle rectAbs = AbsoluteLayout.GetLayoutBounds(absTopic.Children[0]);
            Label lblNew = (Label)absTopic.Children[0];
            hdrLbl.Text = "Label Text " + lblNew.Text;
            hdrLbl.Text += "\n X= " + rectAbs.X + "Y= " + rectAbs.Y + " W= " + rectAbs.Width + " H=" + rectAbs.Height;
            Point p1 = new Point(rectAbs.X, rectAbs.Y);
            //hdrLbl.Text += "Child =" + absTopic.GetChildElements(p1).Count();

Best Answer


  • junejo_aishajunejo_aisha Member ✭✭

    @ElvisXia Thanks for your reply. I also implemented it using Children of the absolute layout.

Sign In or Register to comment.