1

正如您在下面看到的,FlyoutItem有一个 Icon 和一个Title.

    <FlyoutItem Title="About" >
        <FlyoutItem.Icon>
            <FontImageSource FontFamily="MaterialDesignIconFont"
                            Glyph="{StaticResource InformationOutlineGlyph}"
                            Color="Green" />
        </FlyoutItem.Icon>

        <ShellContent Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
    </FlyoutItem>

由于这个Title原因,颜色会自动更改Style

<Style Class="FlyoutItemLayoutStyle" TargetType="Layout" ApplyToDerivedTypes="True">
    <Setter Property="BackgroundColor" Value="LightBlue"></Setter>
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal">
                    <VisualState.Setters>
                        <Setter Property="BackgroundColor" Value="White" />
                        <Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource PrimaryColor}" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="Selected">
                    <VisualState.Setters>
                        <Setter Property="BackgroundColor" Value="{StaticResource PrimaryColor}" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

So the Labelthat is the Titlechanges color automatically when the FlyoutItemis selected. 我需要Icon做同样的事情。我可以使用触发器来设置,FontImageSource但这有其自身的问题。

鉴于TargetName上面的“FlyoutItemLabel” Style,是否可以创建从FontImageSource.Color到 eachFlyoutItem的绑定"FlyoutItemLabel".Color?它必须向上绑定到FlyoutItem祖先,然后向下绑定到<Label x:Name="FlyoutItemLabel" />,不是吗?

4

1 回答 1

0

您可以根据[ItemTemplate][1]需要设置FlyoutItem

<Shell.ItemTemplate>
        <DataTemplate >
            <Grid Style="{StaticResource FloutItemStyle}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.2*" />
                    <ColumnDefinition Width="0.8*" />
                </Grid.ColumnDefinitions>
                <Image Source="{Binding xxx}"
        Margin="5"
        BackgroundColor="{Binding Source={x:Reference label} ,Path=BackgroundColor}"
        HeightRequest="45" />
                <Label Grid.Column="1"
                       x:Name="label"
                       BackgroundColor="Red"
        Text="{Binding Title}"
        FontAttributes="Italic"
        VerticalTextAlignment="Center" />
            </Grid>
        </DataTemplate>
    </Shell.ItemTemplate>
于 2020-12-23T09:13:13.240 回答