简体   繁体   English

如何在 .net maui 菜单栏上获得黑色文本颜色

[英]How to get black text color on .net maui menubar

I am trying to use a MenuBar in .NET MAUI but the text of the MenuBarItem's are showing as white and I can't seem to change them.我正在尝试在 .NET MAUI 中使用 MenuBar,但 MenuBarItem 的文本显示为白色,我似乎无法更改它们。 Anyone know why they are white or how to change them?有谁知道它们为什么是白色的或如何改变它们?

XAML below: XAML 如下:

<Shell
x:Class="SnapSignalTel.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SnapSignalTel"
Shell.FlyoutBehavior="Disabled"
Shell.NavBarIsVisible="True"
Title="{Binding TitleText}"
BackgroundColor="#FFF2F2F2"
>
<Shell.BindingContext>
    <local:MainViewModel />
</Shell.BindingContext>
<Shell.BackButtonBehavior>
    <BackButtonBehavior IsVisible="False" />
</Shell.BackButtonBehavior>
<Shell.MenuBarItems>
    <MenuBarItem Text="File" >
        <MenuFlyoutItem Text="Load" />
        <MenuFlyoutItem Text="Save" />
        <MenuFlyoutItem Text="Exit" />
    </MenuBarItem>
    <MenuBarItem Text="Modes">
    </MenuBarItem>
    <MenuBarItem Text="Help">
    </MenuBarItem>
</Shell.MenuBarItems>

<ShellContent
    Title=""
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage" />

The screenshot below shows the toplevel items white (these are the MenuBarItem's).下面的屏幕截图显示了白色的顶级项目(这些是 MenuBarItem)。 The drop down items are black text though (these are MenuFlyoutItem's)?下拉项目虽然是黑色文本(这些是 MenuFlyoutItem)? Weird and can't seem to change them.很奇怪,似乎无法改变它们。

在此处输入图像描述

Thanks for the help!谢谢您的帮助!

I received and answer on another platform for this same question.我在另一个平台上收到并回答了同样的问题。 Using a Style as below worked.使用如下所示的样式。

<Shell.Resources>
    <Style x:Key="Stylenamehere" TargetType="Element">
        <Setter Property="Shell.BackgroundColor" Value="#FFF2F2F2" />
        <Setter Property="Shell.TitleColor" Value="Black" />
    </Style>
</Shell.Resources>

The above Style is put in the xaml above (in my original post) just below the <Shell...> tag (so just before the BindingContext tag).上面的样式放在上面的 xaml 中(在我的原始帖子中),就在 <Shell...> 标记下方(所以就在 BindingContext 标记之前)。

    <ShellContent
    Title=""
    Style="{StaticResource Stylenamehere}"
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage" />

Then in the <ShellContent... > tag, add the Style as above.然后在 <ShellContent... > 标签中,添加上面的样式。

This then allowed me to change the Text of the menu items using "Shell.TitleColor"这让我可以使用“Shell.TitleColor”更改菜单项的文本

I also removed the (BackgroundColor="#FFF2F2F2") attribute in the XAML in the original post (last item in the <Shell...> tag).我还删除了原始帖子中 XAML 中的 (BackgroundColor="#FFF2F2F2") 属性(<Shell...> 标签中的最后一项)。

So it now looks like this:所以它现在看起来像这样:

<Shell
x:Class="SnapSignalTel.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SnapSignalTel"
Shell.FlyoutBehavior="Disabled"
Shell.NavBarIsVisible="True"
Title="{Binding TitleText}">
<Shell.Resources>
    <Style x:Key="SomeStyleName" TargetType="Element">
        <Setter Property="Shell.BackgroundColor" Value="#FFF2F2F2" />
        <Setter Property="Shell.TitleColor" Value="Black" />
    </Style>
</Shell.Resources>
<Shell.BindingContext>
    <local:MainViewModel />
</Shell.BindingContext>
<Shell.BackButtonBehavior>
    <BackButtonBehavior IsVisible="False" />
</Shell.BackButtonBehavior>

<Shell.MenuBarItems>
    <MenuBarItem Text="File" >
        <MenuFlyoutItem Text="Load" />
        <MenuFlyoutItem Text="Save" />
        <MenuFlyoutItem Text="Exit" />
    </MenuBarItem>
    <MenuBarItem Text="Modes">
    </MenuBarItem>
    <MenuBarItem Text="Help">
    </MenuBarItem>
</Shell.MenuBarItems>

<ShellContent
    Title=""
    Style="{StaticResource SomeStyleName}"
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage" />

</Shell>

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

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