我正在开发一个.NET MAUI的移动软件,我的客户要求我更改导航栏的图标和背景 colored颜色 .

但我的问题是:我无法更改页面中图标的 colored颜色 -我try 在styles.xmlContentPage tag上更改,并使用所需 colored颜色 的图像.但它总是伴随着这个灰色的图标.

为了改变这个 colored颜色 ,我有没有遗漏什么?

This is my bar so far:
Screenshot of the Navigation Bar

这是我试图在代码中更改的内容:

主页

<!-- The color of the icone_home is already white -->
    <ContentPage Title="Início" 
                 BackgroundColor="#F1F1F1" 
                 IconImageSource="icone_home.png" 
                 Shell.TabBarTitleColor="Red" 
                 Shell.TabBarBackgroundColor="Red" 
                 Shell.TabBarDisabledColor="Red" 
                 Shell.TabBarForegroundColor="Red" 
                 Shell.TabBarUnselectedColor="Red">
        ...
    </ContentPage>

Styles.xaml

<!-- Yes, I`ve changed all the colors to test each one -->
<Style TargetType="TabbedPage">
        <Setter Property="BarBackgroundColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource White}}" />
        <Setter Property="BarTextColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource White}}" />
        <Setter Property="UnselectedTabColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource White}}" />
        <Setter Property="SelectedTabColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource White}}" />
    </Style>

    <!-- Did the same thing for NAVIGATION PAGE and SHELL -->

有什么建议我应该在哪里换乘吗?这款应用程序仅适用于iOS.

谢谢!

推荐答案

关于Icons,你可以试着用FontImageSource(如app.xaml).

 <FontImageSource
            x:Key="SearchImageSource"
            FontFamily="FASolid"
            Glyph="{Static fonts:FontAwesomeIcons.MagnifyingGlass}"
            Size="22"
            Color="{AppThemeBinding Dark={StaticResource DarkFontColor},
                                    Light={StaticResource LightFontColor}}"

 />

在您的AppShell中使用

<ShellContent
    Title="Search"
    ContentTemplate="{DataTemplate views:SearchView}"
    Icon="{StaticResource SearchImageSource}"
    Route="SearchView" />

或者如果使用TabbedPage

<NavigationPage Title="Two" IconImageSource="{StaticResource SearchImageSource}">
    <x:Arguments>
        <views:SearchView Title="Search" />
    </x:Arguments>
</NavigationPage>

有关更新选项卡式页面的字体 colored颜色 的信息,请参阅TabbedPage的文档

colored颜色 类型为SelectedTabColor,表示选项卡被选中时的 colored颜色 . UnselectedTabColor,类型为" colored颜色 ",表示选项卡未选中时的 colored颜色 .

<TabbedPage
    x:Class="MauiTest.Views.TestTabbedPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    SelectedTabColor="Red"
    UnselectedTabColor="Azure">

...对于壳牌Tab appearance

TabBarForegroundColor的类型,它定义了选项卡栏的前景色.如果未设置该属性,则使用ForegoundColor属性值. TabBarUnselectedColor,它定义了选项卡栏的未选定 colored颜色 .如果未设置该属性,则使用UnseltedColor属性值.

<Shell.Resources>
    <Style TargetType="TabBar">
        <Setter Property="Shell.TabBarBackgroundColor" Value="LightPink" />
        <Setter Property="Shell.TabBarForegroundColor" Value="White" />
        <Setter Property="Shell.TabBarUnselectedColor" Value="DeepPink" />
    </Style>
</Shell.Resources>

Csharp相关问答推荐

总是丢弃返回的任务和使方法puc无效之间有区别吗?

ASP.NET Core:如何在IPageFilter中注入ApplicationDbContext

通过EFCore上传大量数据.

Microsoft. VisualBasic. FileIO. FileSystem. MoveFile()对话框有错误?

如何修改中间件或其注册以正确使用作用域服务?

如何使用新的Microsoft.IdentityModel.JsonWebToken创建JwtSecurityToken?

为什么EventInfo.EventHandlerType返回可为空的Type值?

在允许溢出的情况下将小数转换为长

HttpClient 415不支持的媒体类型错误

依赖项注入、工厂方法和处置困境

ASP.NET Core MVC将值从视图传递到控制器时出现问题

WinUI 3中DoubleCollection崩溃应用程序类型的依赖属性

源代码生成器:CS8795分部方法';Class1.GetS2(字符串)';必须有实现部分,因为它有可访问性修饰符?

Content WithTargetPath实际上是有效的MSBuild项吗?

在扩展方法中,IEnumerable<;T>;不会转换为IEumerable<;T&>

如何在发布NuGet包之前设置命名空间?

如何在C# WinForm控件中使用Windows 10/11的黑暗主题?

C#中COM对象的实际地址

如何阻止可传递依赖项出现在项目中

除非首先访问使用的终结点,否则本地API上的终结点不起作用