Xamarin 表单网格布局

Xamarin Forms Grid Layouts

我很难在网格上设置文本和图像。这是我需要做的:

所以它基本上看起来像这样:

我试过两种方法。

有人能帮忙吗?

谢谢。

第二种方法的代码:

        Content = new Grid
        {
            //Padding = new Thickness(75, 5, 25, 5),
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.StartAndExpand,

            RowDefinitions =
            {
                new RowDefinition(),
            },

            ColumnDefinitions =
            {
                new ColumnDefinition(),
                new ColumnDefinition(),
            },
        };

        (Content as Grid).RowDefinitions[0].Height = new GridLength(1, GridUnitType.Star);
        (Content as Grid).ColumnDefinitions[0].Width = new GridLength(9, GridUnitType.Star);
        (Content as Grid).ColumnDefinitions[1].Width = new GridLength(1, GridUnitType.Star);

        StackLayout left = new StackLayout
        {
            HorizontalOptions = LayoutOptions.StartAndExpand,
            VerticalOptions = LayoutOptions.Center,
            Orientation = StackOrientation.Vertical,
            Children =
            {
                firstName,
                lastName,
            }
        };

        StackLayout right = new StackLayout
        {
            HorizontalOptions = LayoutOptions.Start,
            VerticalOptions = LayoutOptions.Center,
            Orientation = StackOrientation.Horizontal,
            Children =
            {
                icon,
            }
        };

        (Content as Grid).Children.Add(left, 0, 0);
        (Content as Grid).Children.Add(right, 1, 0);
        //(Content as Grid).Children[1].HorizontalOptions = LayoutOptions.End

现在看起来像这样:

图像应位于网格的最右侧。

谢谢。

在您的 #2 示例中,"right" StackLayout 具有 HorizontalOptions.Start,这意味着它将左对齐。您可能想让它填充它的容器,然后在其中右对齐图像。或者完全摆脱 StackLayout