Search code examples
xamarincoordinateslineshapes

Xamarin Shapes Line Coordinates


I am trying to draw a series of horizontal lines on a Xamarin content page. I cannot make sense out of how Xamarin is interpreting the coordinates. I would have expected this XAML to draw 3 horizontal lines, equally spaced:

    <AbsoluteLayout>
        <StackLayout Orientation="Horizontal" AbsoluteLayout.Bounds="0,0"/>
            <Line X1="5" Y1="0"  X2="30" Y2="0"  AnchorX="0" AnchorY="0"/>
            <Line X1="5" Y1="10" X2="30" Y2="10" AnchorX="0" AnchorY="0"/>
            <Line X1="5" Y1="20" X2="30" Y2="20" AnchorX="0" AnchorY="0"/>
        </StackLayout>
     ...

Instead, the horizontal lines are unevenly spaced. There is more space between the 1st and second lines than the 2nd and 3rd, even though the coordinates define even spacing.

What am I doing wrong here? How does Xamarin Shapes interpret the X/Y coordinates given? Can find 0 docs on this online.


Solution

  • I found that coordinates starting making sense when I moved all the Lines out of the StackLayout. It looks like StackLayout attempts to "move" the elements within it based on the Orientation... even within an AbsoluteLayout with all elements being Anchored at X/Y = 0/0.