垂直文本在侧面菜单xamarin.forms上对齐

时间:2017-08-09 14:05:44

标签: xaml xamarin xamarin.forms cross-platform

我一直试图集中文本 - " Hello Janine Alexander"在这方面的菜单,但无济于事。我试过YAlign =" Center"还有VerticalTextAlignment =" Center"但是它们都没有将它移动一英寸。任何帮助将不胜感激。我确实认为它在导航栏中导致它没有垂直向下移动。我如何解决这个问题

enter image description here

以下是完整的xaml代码:

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="loyaltyworx1.Profile">

    <MasterDetailPage.Master>
        <ContentPage Title="Menu"
                 BackgroundColor="#2196F3">

            <StackLayout Orientation="Vertical">

                <Label x:Name="lblMessage" FontSize="Medium" HorizontalOptions="Center" TextColor="White" />

                <!-- 
             This StackLayout you can use for other
             data that you want to have in your menu drawer
        -->
                <StackLayout BackgroundColor="#2196F3"
                     HeightRequest="150">

                    <Label Text=""
                 FontSize="20"
                 VerticalOptions="CenterAndExpand"
                 TextColor="White"
                 HorizontalOptions="Center"/>
                </StackLayout>

                <ListView x:Name="navigationDrawerList"
                  RowHeight="60"
                  SeparatorVisibility="None"
                  BackgroundColor="White"
                  ItemSelected="OnMenuItemSelected">

                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>

                                <!-- Main design for our menu items -->
                                <StackLayout VerticalOptions="FillAndExpand"
                             Orientation="Horizontal"
                             Padding="20,10,0,10"
                             Spacing="20">

                                    <Image Source="{Binding Icon}"
                         WidthRequest="40"
                         HeightRequest="40"
                         VerticalOptions="Center"
                                           />

                                    <Label Text="{Binding Title}"
                         FontSize="Medium"
                         VerticalOptions="Center"
                         TextColor="#343f42"/>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>

        </ContentPage>
    </MasterDetailPage.Master>

    <MasterDetailPage.Detail>
        <NavigationPage>

        </NavigationPage>
    </MasterDetailPage.Detail>
</MasterDetailPage>

1 个答案:

答案 0 :(得分:0)

看起来您正在将其添加到MasterDetailPage的导航栏中。如果是这样,您将无法将其向下移动。我在我的应用程序上做的是删除MasterDetailPage中的导航栏,在内容页面中我添加了带有绑定的标签,以添加登录用户的名称。

MainPage.xaml中

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:MyApp"
             x:Class="MyApp.MainPage"
             NavigationPage.HasNavigationBar="False">
    <MasterDetailPage.Master>
        <local:MasterPage x:Name ="masterPage"/>
    </MasterDetailPage.Master>

</MasterDetailPage>

MasterPage.xaml

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="MyApp.MasterPage"
                 Padding="0,10,0,0"
                 Icon="hamburger.png"
                 Title="Menu">
        <ContentPage.Content>
            <StackLayout>
                <StackLayout Orientation="Horizontal" Padding="10,10,0,0">
                    <Label Text="&#xf2be;" FontSize="40" FontFamily="FontAwesome" />
                    <Label x:Name="Username" Text="{Binding UserFullName}" VerticalOptions="CenterAndExpand"/>
                </StackLayout>
.....

Screen shot

如果不是问题,请添加包装标签的代码,以便更好地了解可能发生的情况。