我正在开发一个包含4 个选项卡的Xamarin.Forms.Shell 应用程序。我想在所有这些页面上显示一个包含居中 SVG 徽标的公共。 Title
为此,我可以使用TitleView
这样的:
<Shell.TitleView>
<ffimageloadingsvg:SvgCachedImage Source="resource://ShellAppSample.Resources.logoTitle.svg"
DownsampleHeight="6"
HeightRequest="45"/>
</Shell.TitleView>
这很有效,并且徽标很好地位于NavigationBar
. 但是,如果页面包含ToolbarItems
,则徽标不再居中。
例如,在一个页面上我有一个ToolBarItem
这样的:
<ContentPage.ToolbarItems>
<ToolbarItem Text="Refresh"
Order="Primary"
Priority="0"
Command="{Binding RefreshCommand}"
CommandParameter="{x:Reference webView}">
<ToolbarItem.IconImageSource>
<FontImageSource Glyph="{StaticResource FalIconRefresh}"
FontFamily="FontAwesomeLight"
Size="Medium"/>
</ToolbarItem.IconImageSource>
</ToolbarItem>
</ContentPage.ToolbarItems>
是否有另一种方法可以通过使用或计算 SVG 的大小来将SVG 中的居中图像显示为 Title?CustomRenderer
ToolbarItems
我看到一年前已经发布了一个类似的问题,但没有任何解决方案......
我已经尝试过ToolbarItem
像TitleView
这样重绘:
<Shell.TitleView>
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
BackgroundColor="Transparent">
<ffimageloadingsvg:SvgCachedImage Source="resource://ShellAppSample.Resources.blackLogoTitle.svg"
DownsampleHeight="6"
HorizontalOptions="CenterAndExpand"
HeightRequest="45"
BackgroundColor="Transparent"/>
<Image HorizontalOptions="End" VerticalOptions="CenterAndExpand"
BackgroundColor="Transparent">
<Image.Source>
<FontImageSource Glyph="{StaticResource FalIconRefresh}"
FontFamily="FontAwesomeLight"
Size="Medium"/>
</Image.Source>
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding RefreshCommand}" CommandParameter="{x:Reference webView}"/>
</Image.GestureRecognizers>
</Image>
</Grid>
</Shell.TitleView>
在 iOS 上是正确的,但我可以看到:
- 徽标不像不包含任何 的页面那样完全居中
ToolBarItem
,因为当我在页面之间切换时有一个小间隙 - 图标的位置不像我使用
ToolBarItem
在 Android 上,结果不正确:徽标的高度不同,并且图标不在TitleView
.