Xamarin表单-堆栈布局中的中心标题

Xamarin表单-堆栈布局中的中心标题,xamarin,xamarin.forms,Xamarin,Xamarin.forms,下面的屏幕截图显示了包含汉堡菜单和标题的标题。请注意标题是如何在其边界区域(红色框)上居中的。我怎样才能让标题集中在手机的宽度上,而不让汉堡菜单留在原来的位置 下面是创建标题区域的代码 <?xml version="1.0" encoding="UTF-8"?> <ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.co

下面的屏幕截图显示了包含汉堡菜单和标题的标题。请注意标题是如何在其边界区域(红色框)上居中的。我怎样才能让标题集中在手机的宽度上,而不让汉堡菜单留在原来的位置

下面是创建标题区域的代码

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="WP.MobileMidstream.Device.Pages.RunSheetHeader">
    <ContentView.Resources>
        <Style x:Key="HeaderStyle" TargetType="StackLayout">
            <Setter Property="BackgroundColor" Value="#00458C" />
        </Style>
    </ContentView.Resources>
    <ContentView.Content>
        <StackLayout Orientation="Horizontal"
                     HorizontalOptions="FillAndExpand"
                     Style="{StaticResource HeaderStyle}">
            <StackLayout.HeightRequest>
                <OnPlatform x:TypeArguments="x:Double">
                    <On Platform="iOS">80</On>
                    <On Platform="Android">56</On>
                </OnPlatform>
            </StackLayout.HeightRequest>
            <Image Source="hamburger_icon" 
                   Margin="10" />
            <Label VerticalTextAlignment="Center"
                   HorizontalTextAlignment="Center"
                   HorizontalOptions="FillAndExpand"
                   FontSize="20"
                   BackgroundColor="Red"
                   TextColor="White">Daily Run Sheet</Label>
        </StackLayout>
    </ContentView.Content>
</ContentView>

80
56
每日运行表

@Jason建议使用网格代替StackLayout。这是我想出的有效方法。谢谢@Jason


80
56
每日运行表

我将使用网格(1行x 2列)代替。让标签延伸到两个COL,然后将汉堡包图标仅放在第一个单元格中,在标签i同意@Jason之后,您应该为此应用程序使用网格。一般来说,您应该尽量避免使用
StackLayout
,因为在屏幕上显示会非常昂贵。网格对于xamarin表单ui来说是一个非常有用的工具!
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="WP.MobileMidstream.Device.Pages.RunSheetHeader">
    <ContentView.Resources>
        <Style x:Key="HeaderStyle" TargetType="Grid">
            <Setter Property="BackgroundColor" Value="#00458C" />
        </Style>
    </ContentView.Resources>
    <ContentView.Content>
        <Grid Style="{StaticResource HeaderStyle}">
            <Grid.RowDefinitions>
                <RowDefinition>
                    <RowDefinition.Height>
                        <OnPlatform x:TypeArguments="GridLength">
                            <On Platform="iOS">80</On>
                            <On Platform="Android">56</On>
                        </OnPlatform>
                    </RowDefinition.Height>
                </RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0"
                   Grid.Column="0"
                   Grid.ColumnSpan="2"
                   VerticalTextAlignment="Center"
                   HorizontalTextAlignment="Center"
                   HorizontalOptions="Fill"
                   FontSize="20"
                   TextColor="White">Daily Run Sheet</Label>
            <Image Source="hamburger_icon" 
                   Grid.Row="0"
                   Grid.Column="0"
                   Margin="10" />
        </Grid>
    </ContentView.Content>
</ContentView>