我正在使用 .NET MAUI 创建桌面应用程序。
在这里,我有一个ContentPage
与标题My title.
<ContentPage
x:Class="MAUI.Desktop.Pages.PlanningPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="My title">
....
Its title is aligned left by default, do you know how to align it to the center of the page? If possible, I also want to add more style to it too.
编辑:建议的解决方案
- 我忘了提及我的页面已被考虑
NavigationPage
。所以,这是我的解决方案:
<ContentPage
x:Class="MAUI.Desktop.Pages.PlanningPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
>
<NavigationPage.TitleView>
<Label
x:Name="pageTitleView"
HorizontalTextAlignment="Center"
Text="My title"/>
</NavigationPage.TitleView>
......
在代码隐藏中xaml.cs
file:
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
pageTitleView.WidthRequest = width;
}
- 如果您正在与
Shell app
,你可以按照来自@mm8的回答 https://stackoverflow.com/a/74657045/12020710
你可以定义你自己的TitleView
:
<ContentPage x:Class="MAUI.Desktop.Pages.PlanningPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Planification">
<Shell.TitleView>
<Grid>
<Label Text="My Title" HorizontalOptions="Center" VerticalOptions="Center" />
</Grid>
</Shell.TitleView>
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)