我正在开发一个Xamarin.Forms.Shell应用程序,其中包含4选项卡。我想在所有这些页面上显示一个公共 Title,其中包含一个以为中心的SVG徽标。
为此,我可以使用像这样的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>是否有另一种方法通过使用或计算ToolbarItems的大小从SVG显示以CustomRenderer为标题的图像
我看到相似问题已经在一年前发布了,但是没有任何解决方案.
我已经尝试过像这样在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时那样定位ToolBarItem在安卓系统上,结果是不正确的:徽标的高度不一样,图标不在TitleView。
发布于 2020-11-20 09:15:36
最后,我像这样管理了我的TitleView:
对于Image
<Shell.TitleView >
<Image Source="resource://ShellAppSample.Resources.logo.jpg"
VerticalOptions="CenterAndExpand" HorizontalOptions="Center"
Margin="{OnPlatform Android='0,0,16,0', Default=0}"/>
</Shell.TitleView>对于Label
<Shell.TitleView>
<Label Text="{Binding Title}"
VerticalOptions="CenterAndExpand" HorizontalOptions="Center"
Margin="{OnPlatform Android='0,0,16,0', Default=0}"/>
</Shell.TitleView>和Label的一个“中等”大小的ToolBarItem
<Shell.TitleView>
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Title}"
Grid.Column="1"
VerticalOptions="CenterAndExpand" HorizontalOptions="Center"
Margin="{OnPlatform Android='0,0,16,0', Default=0}"/>
</Grid>
</Shell.TitleView>
<ContentPage.ToolbarItems>
<ToolbarItem Text="Refresh"
Order="Primary"
Priority="1"
Command="{Binding RefreshCommand}">
<ToolbarItem.IconImageSource>
<FontImageSource Glyph="{StaticResource FalIconRefresh}"
FontFamily="FontAwesomeLight"
Size="Medium"/>
</ToolbarItem.IconImageSource>
</ToolbarItem>
</ContentPage.ToolbarItems>我已经检查了DebugRainbows包的对齐情况,在iOS/Android上,在小型/大型设备上,它看起来都很好。
这并不完美,如果我添加其他ToolBarItem,我需要更新规则,但是它是这样工作的。
https://stackoverflow.com/questions/64767959
复制相似问题