xaml maui – how to change the color of the tab selector of a flyout menu?

huangapple go评论55阅读模式
英文:

xaml maui - how to change the color of the tab selector of a flyout menu?

问题

I'll provide translations for the code parts you've shared:

DATA TEMPLATE

<DataTemplate>
    <Grid Style="{StaticResource FlyoutItemStyle}" WidthRequest="280" ColumnDefinitions="Auto, *"
          Padding="0, 10, 0, 10">
        <Image Source="{Binding FlyoutIcon}"
               Margin="10"
               VerticalOptions="Center"
               HorizontalOptions="Center"
               HeightRequest="38"
               WidthRequest="38" />

        <Label Grid.Column="1" 
               Text="{Binding Title}" 
               FontSize="12"
               HorizontalOptions="StartAndExpand"
               VerticalOptions="Center"
               x:Name="_label">
            <Label.Style>
                <Style TargetType="Label">
                    <Setter Property="TextColor" Value="{StaticResource AusDx_Gold}" />
                    <Style.Triggers>
                        <DataTrigger TargetType="Label" Binding="{Binding IsEnabled}" Value="False">
                            <Setter Property="TextColor"  Value="{StaticResource AusDx_Blue}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Label.Style>
        </Label>
    </Grid>
</DataTemplate>

STYLES

<Style x:Key="FlyoutItemStyle" TargetType="Grid">
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal" />
                <VisualState x:Name="Selected">
                    <VisualState.Setters>
                        <Setter Property="BackgroundColor" Value="LightGray"/>
                        <Setter TargetName="_label" Property="Label.TextColor" Value="Black" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

Please note that I've only translated the code portions as requested. If you need any further assistance or have specific questions, feel free to ask.

英文:

not sure what the element is actually called so open to changes to the question.

I want to change the color of whatever this is called. I've included the code for my DataTemplate as well as my styles for the menu as I assume its something to do with those.

xaml maui – how to change the color of the tab selector of a flyout menu?

DATA TEMPLATE

                  &lt;DataTemplate&gt;
                    &lt;Grid Style=&quot;{StaticResource FlyoutItemStyle}&quot; WidthRequest=&quot;280&quot; ColumnDefinitions=&quot;Auto, *&quot; Padding=&quot;0, 10, 0, 10&quot;&gt;
                        &lt;Image Source=&quot;{Binding FlyoutIcon}&quot;
                         Margin=&quot;10&quot;
                         VerticalOptions=&quot;Center&quot;
                         HorizontalOptions=&quot;Center&quot;
                         HeightRequest=&quot;38&quot;
                         WidthRequest=&quot;38&quot; /&gt;

                        &lt;Label Grid.Column=&quot;1&quot; 
                         Text=&quot;{Binding Title}&quot; 
                         FontSize=&quot;12&quot;
                         HorizontalOptions=&quot;StartAndExpand&quot;
                         VerticalOptions=&quot;Center&quot;
                         x:Name=&quot;_label&quot;&gt;
                            &lt;Label.Style&gt;
                                &lt;Style TargetType=&quot;Label&quot;&gt;
                                    &lt;Setter Property=&quot;TextColor&quot; Value=&quot;{StaticResource AusDx_Gold}&quot; /&gt;
                                    &lt;Style.Triggers&gt;
                                        &lt;DataTrigger TargetType=&quot;Label&quot; Binding=&quot;{Binding IsEnabled}&quot; Value=&quot;False&quot;&gt;
                                            &lt;Setter Property=&quot;TextColor&quot;  Value=&quot;{StaticResource AusDx_Blue}&quot; /&gt;
                                        &lt;/DataTrigger&gt;
                                    &lt;/Style.Triggers&gt;
                                &lt;/Style&gt;
                            &lt;/Label.Style&gt;
                        &lt;/Label&gt;
                    &lt;/Grid&gt;
                &lt;/DataTemplate&gt;

STYLES

&lt;Style x:Key=&quot;FlyoutItemStyle&quot; TargetType=&quot;Grid&quot;&gt;
        &lt;Setter Property=&quot;VisualStateManager.VisualStateGroups&quot;&gt;
            &lt;VisualStateGroupList&gt;
                &lt;VisualStateGroup x:Name=&quot;CommonStates&quot;&gt;
                    &lt;VisualState x:Name=&quot;Normal&quot; /&gt;
                    &lt;VisualState x:Name=&quot;Selected&quot;&gt;
                        &lt;VisualState.Setters&gt;
                            &lt;Setter Property=&quot;BackgroundColor&quot; Value=&quot;LightGray&quot;/&gt;
                            &lt;Setter TargetName=&quot;_label&quot; Property=&quot;Label.TextColor&quot; Value=&quot;Black&quot; /&gt;
                        &lt;/VisualState.Setters&gt;
                    &lt;/VisualState&gt;
                &lt;/VisualStateGroup&gt;
            &lt;/VisualStateGroupList&gt;
        &lt;/Setter&gt;
    &lt;/Style&gt;

Any help or guidance is greatly appreciated! xaml maui – how to change the color of the tab selector of a flyout menu?

答案1

得分: 1

这个选择选项卡可以在Windows的App.xaml中的maui中进行更改。
你可以将这段代码添加到Platforms->Windows->App.xaml文件中。

<maui:MauiWinUIApplication.Resources>
    <StaticResource x:Key="NavigationViewSelectionIndicatorForeground" ResourceKey="SystemControlForegroundAccentBrush" />
    <SolidColorBrush x:Key="SystemControlForegroundAccentBrush" Color="Red" />
</maui:MauiWinUIApplication.Resources>

要查看更多样式,请参阅WinUI源代码CommonStyles

英文:

This select tab can be changed in the maui in windows/App.xaml.
You can add this code to Platforms->Windows-> App.xaml file.

&lt;maui:MauiWinUIApplication.Resources&gt;
        &lt;StaticResource x:Key=&quot;NavigationViewSelectionIndicatorForeground&quot; ResourceKey=&quot;SystemControlForegroundAccentBrush&quot; /&gt;
        &lt;SolidColorBrush x:Key=&quot;SystemControlForegroundAccentBrush&quot;  Color=&quot;Red&quot; /&gt;
&lt;/maui:MauiWinUIApplication.Resources&gt;

For more styles, you can see the WinUI source code CommonStyles.

huangapple
  • 本文由 发表于 2023年5月17日 12:48:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268640.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定