Xamarin.forms Xamarin表单弹出菜单文本颜色

Xamarin.forms Xamarin表单弹出菜单文本颜色,xamarin.forms,styles,xamarin.forms.shell,Xamarin.forms,Styles,Xamarin.forms.shell,我目前正在研究Xamarin Forms Shell应用程序的样式方面,目前无法找到如何更改弹出菜单TextColor <Shell xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MainShellPage" xmlns:ios="

我目前正在研究Xamarin Forms Shell应用程序的样式方面,目前无法找到如何更改弹出菜单TextColor

<Shell xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   x:Class="MainShellPage"
   xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"      
   NavigationPage.HasBackButton="False" 
   FlyoutBackgroundColor="{StaticResource Grey}"
   BackgroundColor="{StaticResource Grey}"
   IsBusy="{Binding IsBusy}"
   BindingContext="{Binding MainShell, Source={StaticResource ViewModelLocator}}"
   Navigated="MainShellPage_OnNavigated">
<Shell.Resources>
    <Style x:Key="BaseStyle"
           TargetType="Element">
        <Setter Property="Shell.BackgroundColor"
                Value="{StaticResource Grey}" />
        <Setter Property="Shell.ForegroundColor"
                Value="{StaticResource White}" />
        <Setter Property="Shell.TitleColor"
                Value="{StaticResource White}" />
        <Setter Property="Shell.DisabledColor"
                Value="#B4FFFFFF" />
        <Setter Property="Shell.UnselectedColor"
                Value="#95FFFFFF" />
    </Style>
</Shell.Resources>
<Shell.FlyoutHeaderTemplate>
    <DataTemplate>
        <StackLayout BackgroundColor="{StaticResource Grey}" HeightRequest="180"
                     Orientation="Vertical">
            <Image Source="mobile_logo" HorizontalOptions="Center" VerticalOptions="Start"
                   WidthRequest="160"/>
            <Label Text="{Binding TeamName}" TextColor="{StaticResource White}" FontAttributes="Bold"
                   HorizontalOptions="Center" />
            <Label Text="{Binding UserFullName}" TextColor="{StaticResource White}"
                   HorizontalOptions="Center" />
            <Label Text="{Binding UserEmail}" TextColor="{StaticResource White}"
                   HorizontalOptions="Center" />
            <Label Text="{Binding Version}" TextColor="{StaticResource White}" VerticalOptions="End"
                   HorizontalOptions="End" Margin="0, 10, 0, 0" FontSize="10" />
        </StackLayout>
    </DataTemplate>
</Shell.FlyoutHeaderTemplate>

<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
    <Tab Title="TabOne" Style="{StaticResource BaseStyle}"
         Route="tabone">
        <Tab.Icon>
            <FontImageSource
                Glyph="{Binding TabOneGlyph, Source={StaticResource MainShellGlyphHelper}}"
                FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
        </Tab.Icon>
        <ShellContent Title="TabOne"  ContentTemplate="{DataTemplate pages:TabOnePage}" />
    </Tab>
    <Tab Title="TabTwo" Style="{StaticResource BaseStyle}"
         Route="tabtwo">
        <Tab.Icon>
            <FontImageSource
                Glyph="{Binding TabTwoGlyph, Source={StaticResource MainShellGlyphHelper}}"
                FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
        </Tab.Icon>
        <ShellContent ContentTemplate="{DataTemplate pages:TabTwoPage}" />
    </Tab>        
</FlyoutItem>


<MenuItem />
<MenuItem />
<MenuItem />
<MenuItem
    Text="MenuItemOne"
    Command="{Binding MenuItemOneCommand}">
    <MenuItem.IconImageSource>
        <FontImageSource Glyph="{Binding MenuItemOneGlyph, Source={StaticResource MainShellGlyphHelper}}"
                         FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
    </MenuItem.IconImageSource>
</MenuItem> 
我尝试为标签TextColor添加一个样式,BasedOn是我正在使用的基本样式,但是文本颜色仍然没有改变,或者它改变了所有标签的TextColor

<Shell xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   x:Class="MainShellPage"
   xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"      
   NavigationPage.HasBackButton="False" 
   FlyoutBackgroundColor="{StaticResource Grey}"
   BackgroundColor="{StaticResource Grey}"
   IsBusy="{Binding IsBusy}"
   BindingContext="{Binding MainShell, Source={StaticResource ViewModelLocator}}"
   Navigated="MainShellPage_OnNavigated">
<Shell.Resources>
    <Style x:Key="BaseStyle"
           TargetType="Element">
        <Setter Property="Shell.BackgroundColor"
                Value="{StaticResource Grey}" />
        <Setter Property="Shell.ForegroundColor"
                Value="{StaticResource White}" />
        <Setter Property="Shell.TitleColor"
                Value="{StaticResource White}" />
        <Setter Property="Shell.DisabledColor"
                Value="#B4FFFFFF" />
        <Setter Property="Shell.UnselectedColor"
                Value="#95FFFFFF" />
    </Style>
</Shell.Resources>
<Shell.FlyoutHeaderTemplate>
    <DataTemplate>
        <StackLayout BackgroundColor="{StaticResource Grey}" HeightRequest="180"
                     Orientation="Vertical">
            <Image Source="mobile_logo" HorizontalOptions="Center" VerticalOptions="Start"
                   WidthRequest="160"/>
            <Label Text="{Binding TeamName}" TextColor="{StaticResource White}" FontAttributes="Bold"
                   HorizontalOptions="Center" />
            <Label Text="{Binding UserFullName}" TextColor="{StaticResource White}"
                   HorizontalOptions="Center" />
            <Label Text="{Binding UserEmail}" TextColor="{StaticResource White}"
                   HorizontalOptions="Center" />
            <Label Text="{Binding Version}" TextColor="{StaticResource White}" VerticalOptions="End"
                   HorizontalOptions="End" Margin="0, 10, 0, 0" FontSize="10" />
        </StackLayout>
    </DataTemplate>
</Shell.FlyoutHeaderTemplate>

<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
    <Tab Title="TabOne" Style="{StaticResource BaseStyle}"
         Route="tabone">
        <Tab.Icon>
            <FontImageSource
                Glyph="{Binding TabOneGlyph, Source={StaticResource MainShellGlyphHelper}}"
                FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
        </Tab.Icon>
        <ShellContent Title="TabOne"  ContentTemplate="{DataTemplate pages:TabOnePage}" />
    </Tab>
    <Tab Title="TabTwo" Style="{StaticResource BaseStyle}"
         Route="tabtwo">
        <Tab.Icon>
            <FontImageSource
                Glyph="{Binding TabTwoGlyph, Source={StaticResource MainShellGlyphHelper}}"
                FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
        </Tab.Icon>
        <ShellContent ContentTemplate="{DataTemplate pages:TabTwoPage}" />
    </Tab>        
</FlyoutItem>


<MenuItem />
<MenuItem />
<MenuItem />
<MenuItem
    Text="MenuItemOne"
    Command="{Binding MenuItemOneCommand}">
    <MenuItem.IconImageSource>
        <FontImageSource Glyph="{Binding MenuItemOneGlyph, Source={StaticResource MainShellGlyphHelper}}"
                         FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
    </MenuItem.IconImageSource>
</MenuItem> 

还有另一种方法,您可以像设置标题一样将ItemTemplate设置到弹出按钮,然后可以为文本设置颜色:

<Shell.ItemTemplate>
    <DataTemplate>
        <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <!-- Icon -->
                    <ColumnDefinition Width="*"/>
                    <!-- Title-->
                    <ColumnDefinition Width="2*"/>
                </Grid.ColumnDefinitions>
                <!-- Icon -->
                 <Label  Grid.Column="0"
                         Margin="20,0,0,0"
                         VerticalOptions="Center"
                         HorizontalTextAlignment="Center"
                         HorizontalOptions="Center"
                         Text="{Binding Icon}" 
                         FontFamily="{StaticResource FontAwesome}" 
                         FontSize="26"
                         TextColor="{StaticResource White}"/>
                <!-- Label -->
                <Label Grid.Column="1" 
                       Text="{Binding Title}" 
                       FontSize="23" 
                       VerticalOptions="Center"
                       VerticalTextAlignment="Center"
                       TextColor="[ Here you can insert the colour you want]"
                       HorizontalOptions="Start"  />
            </Grid>
    </DataTemplate>
</Shell.ItemTemplate>

然后,要使用它:

<FlyoutItem Title="TabOne"
            Icon="{Binding TabOneGlyph, Source={StaticResource 
                   MainShellGlyphHelper}}">
    <ShellContent ContentTemplate="{DataTemplate pages:TabOnePage}"/>
</FlyoutItem>

当我确定Shell时,我在我的大多数项目中都在使用这种技术

下面是我做的一个项目的例子:

我希望这对你有帮助 我目前无法找到如何更改弹出式菜单文本颜色

<Shell xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   x:Class="MainShellPage"
   xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"      
   NavigationPage.HasBackButton="False" 
   FlyoutBackgroundColor="{StaticResource Grey}"
   BackgroundColor="{StaticResource Grey}"
   IsBusy="{Binding IsBusy}"
   BindingContext="{Binding MainShell, Source={StaticResource ViewModelLocator}}"
   Navigated="MainShellPage_OnNavigated">
<Shell.Resources>
    <Style x:Key="BaseStyle"
           TargetType="Element">
        <Setter Property="Shell.BackgroundColor"
                Value="{StaticResource Grey}" />
        <Setter Property="Shell.ForegroundColor"
                Value="{StaticResource White}" />
        <Setter Property="Shell.TitleColor"
                Value="{StaticResource White}" />
        <Setter Property="Shell.DisabledColor"
                Value="#B4FFFFFF" />
        <Setter Property="Shell.UnselectedColor"
                Value="#95FFFFFF" />
    </Style>
</Shell.Resources>
<Shell.FlyoutHeaderTemplate>
    <DataTemplate>
        <StackLayout BackgroundColor="{StaticResource Grey}" HeightRequest="180"
                     Orientation="Vertical">
            <Image Source="mobile_logo" HorizontalOptions="Center" VerticalOptions="Start"
                   WidthRequest="160"/>
            <Label Text="{Binding TeamName}" TextColor="{StaticResource White}" FontAttributes="Bold"
                   HorizontalOptions="Center" />
            <Label Text="{Binding UserFullName}" TextColor="{StaticResource White}"
                   HorizontalOptions="Center" />
            <Label Text="{Binding UserEmail}" TextColor="{StaticResource White}"
                   HorizontalOptions="Center" />
            <Label Text="{Binding Version}" TextColor="{StaticResource White}" VerticalOptions="End"
                   HorizontalOptions="End" Margin="0, 10, 0, 0" FontSize="10" />
        </StackLayout>
    </DataTemplate>
</Shell.FlyoutHeaderTemplate>

<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
    <Tab Title="TabOne" Style="{StaticResource BaseStyle}"
         Route="tabone">
        <Tab.Icon>
            <FontImageSource
                Glyph="{Binding TabOneGlyph, Source={StaticResource MainShellGlyphHelper}}"
                FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
        </Tab.Icon>
        <ShellContent Title="TabOne"  ContentTemplate="{DataTemplate pages:TabOnePage}" />
    </Tab>
    <Tab Title="TabTwo" Style="{StaticResource BaseStyle}"
         Route="tabtwo">
        <Tab.Icon>
            <FontImageSource
                Glyph="{Binding TabTwoGlyph, Source={StaticResource MainShellGlyphHelper}}"
                FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
        </Tab.Icon>
        <ShellContent ContentTemplate="{DataTemplate pages:TabTwoPage}" />
    </Tab>        
</FlyoutItem>


<MenuItem />
<MenuItem />
<MenuItem />
<MenuItem
    Text="MenuItemOne"
    Command="{Binding MenuItemOneCommand}">
    <MenuItem.IconImageSource>
        <FontImageSource Glyph="{Binding MenuItemOneGlyph, Source={StaticResource MainShellGlyphHelper}}"
                         FontFamily="{StaticResource FontAwesome}" Color="{StaticResource White}" />
    </MenuItem.IconImageSource>
</MenuItem> 
从中,Shell包括三个样式类,它们自动应用于
弹出项
菜单项
对象。样式类名称为
FlyoutItemLabelStyle
FlyoutItemImageStyle
,以及
FlyoutItemLayoutStyle

如果要更改弹出式菜单文字颜色,可以创建新样式并使用弹出式菜单项标签样式更改弹出式菜单文字颜色

  <Style Class="FlyoutItemLabelStyle" TargetType="Label">
            <Setter Property="TextColor" Value="Red" />
        </Style>

从中,每个ShellContent对象只能通过弹出式按钮项访问,而不能通过选项卡访问。这是因为默认情况下,仅当弹出项包含多个选项卡时,才会显示选项卡

因此,如果要显示弹出式菜单,则需要在弹出式菜单项中添加选项卡

<FlyoutItem Title="About" Icon="icon_about.png">
    <Tab>
        <ShellContent ContentTemplate="{DataTemplate local:AboutPage}" Route="AboutPage" />
    </Tab>
</FlyoutItem>
<FlyoutItem Title="Browse" Icon="icon_feed.png">
    <Tab>
        <ShellContent ContentTemplate="{DataTemplate local:ItemsPage}" Route="ItemsPage" />
    </Tab>
</FlyoutItem>


感谢您使用FlyoutItemLabelStyle类,它完全符合我的要求。