【发布时间】:2021-04-01 20:10:00
【问题描述】:
如下所示,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>
所以Label 即Title 在选择FlyoutItem 时会自动改变颜色。我需要Icon 来做同样的事情。我可以使用触发器来设置FontImageSource,但这有它自己的问题。
鉴于上述Style 中的TargetName“FlyoutItemLabel”,是否可以创建从FontImageSource.Color 到每个FlyoutItem 的"FlyoutItemLabel".Color 的绑定?它必须向上绑定到FlyoutItem 祖先,然后向下绑定到<Label x:Name="FlyoutItemLabel" />,不是吗?
【问题讨论】:
标签: xaml xamarin.forms data-binding xamarin.forms.shell