Xaml 侧边菜单xamarin.forms上的垂直文本对齐
我一直试图集中文本-“你好,詹妮亚历山大”在这侧菜单,但没有任何效果。我已经尝试过YAlign=“Center”和VerticalTextAlignment=“Center”,但都没有向下移动一英寸。任何帮助都将不胜感激。我确实认为它在导航栏中,导致它不能垂直向下移动。我该如何解决这个问题 以下是完整的xaml代码:Xaml 侧边菜单xamarin.forms上的垂直文本对齐,xaml,xamarin,xamarin.forms,cross-platform,Xaml,Xamarin,Xamarin.forms,Cross Platform,我一直试图集中文本-“你好,詹妮亚历山大”在这侧菜单,但没有任何效果。我已经尝试过YAlign=“Center”和VerticalTextAlignment=“Center”,但都没有向下移动一英寸。任何帮助都将不胜感激。我确实认为它在导航栏中,导致它不能垂直向下移动。我该如何解决这个问题 以下是完整的xaml代码: <?xml version="1.0" encoding="utf-8" ?> <MasterDetailPage xmlns="http://xamarin.
<?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>
看起来您正在将其添加到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="" FontSize="40" FontFamily="FontAwesome" />
<Label x:Name="Username" Text="{Binding UserFullName}" VerticalOptions="CenterAndExpand"/>
</StackLayout>
.....
.....
如果这不是问题所在,请添加包装标签的代码,以便更好地了解可能发生的情况。看起来您正在将其添加到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="" FontSize="40" FontFamily="FontAwesome" />
<Label x:Name="Username" Text="{Binding UserFullName}" VerticalOptions="CenterAndExpand"/>
</StackLayout>
.....
.....
如果这不是问题所在,请添加包装标签的代码,以便更好地了解可能发生的情况。谢谢@11011,我已经添加了完整的xaml,我需要在那里更改什么才能使其正常工作?Thanks@Unicorn_Girl我复制了您的代码并将其添加到project中。一切正常,菜单显示正确。我不知道为什么它不能正确地显示在你这边。您是否在Android项目(styles.xml)中添加了自定义的菜单,或者您是否使用了一些支持的代码来更改菜单的高度,使其延伸到操作栏后面?谢谢。我让它工作,我忽略了“VerticalOptions=”CenterAndExpand“并使用了“Center”“相反。谢谢你的帮助!:)谢谢@11011,我已经添加了完整的xaml,我需要在那里做什么更改才能让它正常工作?Thanks@Unicorn_Girl我复制了您的代码并将其添加到project中。一切正常,菜单显示正确。我不知道为什么它不能正确地显示在你这边。您是否在Android项目(styles.xml)中添加了自定义的菜单,或者您是否使用了一些支持的代码来更改菜单的高度,使其延伸到操作栏后面?谢谢。我让它工作了,我忽略了“VerticalOptions=“CenterAndExpand”,而是使用了“Center”。谢谢你的帮助!:)