简体   繁体   English

Xamarin Forms Shell ItemTemplate 样式

[英]Xamarin Forms Shell ItemTemplate Style

How to change lable's color which is inside grid of FlyoutItem?如何更改 FlyoutItem 网格内的标签颜色? In the above code I tried to change grid's background color and lable's font color when a specific menu item is selected.在上面的代码中,我尝试在选择特定菜单项时更改网格的背景颜色和标签的字体颜色。 Grid's background changes.网格的背景变化。 But font color doesn't.但字体颜色没有。 Styles:款式:

<Shell.Resources>
    <Style x:Key="FloutItemStyle" TargetType="Grid">
        <Setter Property="VisualStateManager.VisualStateGroups">
            <VisualStateGroupList>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor" Value="Orange"/>
                        </VisualState.Setters>
                    </VisualState>
                    <VisualState x:Name="Selected">
                        <VisualState.Setters>
                            <Setter Property="BackgroundColor" Value="DarkOrange"/>
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateGroupList>
        </Setter>
    </Style>
    <Style x:Key="FlyoutLabelStyle" TargetType="Label">
        <Setter Property="VisualStateManager.VisualStateGroups">
            <VisualStateGroupList>
                <VisualStateGroup>
                    <VisualState x:Name="Normal">
                        <VisualState.Setters>
                            <Setter Property="TextColor" Value="Black"/>
                        </VisualState.Setters>
                    </VisualState>
                    <VisualState x:Name="Selected">
                        <VisualState.Setters>
                            <Setter Property="TextColor" Value="DarkGray"/>
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateGroupList>
        </Setter>
    </Style>
</Shell.Resources>

Shell ItemTemplate:外壳项目模板:

<DataTemplate >
        <Grid Style="{StaticResource FloutItemStyle}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.2*" />
                <ColumnDefinition Width="0.8*" />
            </Grid.ColumnDefinitions>
            <Image Source="{Binding FlyoutIcon}"
                Margin="5"
                HeightRequest="45" />
            <Label Style="{StaticResource FlyoutLabelStyle}" 
                Grid.Column="1"
                FontSize="Large"
                Text="{Binding Title}"
                FontAttributes="Bold"
                VerticalTextAlignment="Center" />
        </Grid>
    </DataTemplate>

You can try using Triggers.您可以尝试使用触发器。

 <Label Grid.Column="1"
                       TextColor="Black"
                       Text="{Binding Title}"
                       FontAttributes="Italic"
                       VerticalTextAlignment="Center" >
                <Label.Triggers>
                    <DataTrigger TargetType="Label" Binding="{Binding Source={x:Reference grid},Path=BackgroundColor}" Value="Accent">
                        <Setter Property="TextColor" Value="White"/>
                    </DataTrigger>
                </Label.Triggers>
            </Label>

for reference 以供参考

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

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