简体   繁体   English

ContentPage 标题不适用于 .NET MAUI Android 应用程序

[英]ContentPage title doesn't work on .NET MAUI Android application

I try to create a title image for MAUI Android application, but the title is not visible.我尝试为 MAUI Android 应用程序创建标题图像,但标题不可见。 Even if I change with a label, same result:即使我更改为 label,结果也相同:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ChapsPizza.Views.MainPage"
             xmlns:vm="clr-namespace:ChapsPizza.ViewModels"
             Title="Test">
    
    <NavigationPage.TitleView>
        <Label Text="Test" TextColor="Black"/>
        <!--<Image Source="logo.png" Background="Orange"
            VerticalOptions="CenterAndExpand" 
            HorizontalOptions="CenterAndExpand"
            HeightRequest="40" WidthRequest="40"/>-->
    </NavigationPage.TitleView>

    <ContentPage.BindingContext>
        <vm:MainPageViewModel/>
    </ContentPage.BindingContext>

</ContentPage>

How can I fix this?我怎样才能解决这个问题?

This potential issue is being fixed and tracked on this thread: https://github.com/do.net/maui/issues/3877这个潜在的问题正在这个线程上被修复和跟踪: https://github.com/do.net/maui/issues/3877

I tested it using Visual Studio 17.3.5 and the label in the TitleView was shown in the contentpage.我使用Visual Studio 17.3.5对其进行了测试,内容页面中显示了label中的TitleView

Update:更新:

In your AppShell.xaml.cs , change it like below:在您的AppShell.xaml.cs中,将其更改如下:

MainPage = new NavigationPage(new MainPage());

Use Shell.TitleView使用 Shell.TitleView

<Shell.TitleView>
    <Label Text="Test" TextColor="Black"/>
</Shell.TitleView>

As I understand we should not use NavigationPage but I'm not sure.据我了解,我们不应该使用 NavigationPage,但我不确定。

NavigationPage is incompatible with .NET MAUI Shell apps, and an exception will be thrown if you attempt to use NavigationPage in a Shell app. NavigationPage与.NET MAUI Shell应用不兼容,在Shell应用中尝试使用NavigationPage会抛出异常。 For more information about Shell apps, see Shell.有关 Shell 应用程序的更多信息,请参阅 Shell。

https://learn.microsoft.com/en-us/do.net/maui/user-interface/pages/navigationpage?view.net-maui-7.0 https://learn.microsoft.com/en-us/do.net/maui/user-interface/pages/navigationpage?view.net-maui-7.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM