【发布时间】:2022-06-16 23:44:49
【问题描述】:
我正在为我现有的 Xamarin Forms android 应用添加 iOS 支持。
iOS 上不显示工具栏项、导航返回箭头和汉堡菜单:
Application.MainPage 设置为 Shell:
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="app.MainPage"
FlyoutBackgroundColor="{StaticResource cBackgroundColorDark}"
Shell.TabBarTitleColor="{StaticResource cBackgroundColor}"
Shell.BackgroundColor="{StaticResource cBackgroundColor}">
<Shell.Resources>
<ResourceDictionary>
<vm:FlyoutVM x:Key="vm" x:Name="vm"/>
</ResourceDictionary>
</Shell.Resources>
<Shell.FlyoutHeader>
</Shell.FlyoutHeader>
<ShellContent Title="page1"
IsTabStop="True"
ContentTemplate="{DataTemplate views:Page1Page}"/>
...
<Shell.FlyoutContent>
</Shell.FlyoutContent>
<Shell.FlyoutFooter>
</Shell.FlyoutFooter>
</Shell>
带有工具栏项的页面很简单:
<ContentPage>
<ContentPage.ToolbarItems>
<ToolbarItem Text="Example"
IconImageSource="Example.png"
Clicked="ExampleToolbarItem_Clicked"
/>
</ContentPage.ToolbarItems>
</ContentPage>
所有导航(汉堡菜单、后退按钮等)和工具栏项目都可以在 iOS 上点击并按预期工作 - 它们只是不可见。
我不明白为什么这在 iOS 上不起作用,有什么建议吗?
(我找不到任何可能使其行为不同的样式。我也尝试过仅显示文本(无图标)的工具栏,但问题仍然存在)
如果需要,我可以提供更多代码。
编辑
我最终创建了一个新的 Xamarin shell 模板项目并将所有内容移过来。这解决了问题...
【问题讨论】:
-
这些图像存储在哪里?如果它们是资源,您是否确保 iOS 资源具有 Properties/Build Action = BundleResource?
-
另外,确认它们没有默认为与条形背景相同的颜色。
-
感谢您的建议,但可惜没有修复。这些图像是 BundledResources,我可以加载不在标签栏上的图像。我可以将条形背景颜色缩小到 Shell.BackgroundColor="{StaticResource cBackgroundColor}",但我没有看到任何会影响图像的地方引用了这个 StaticResource。
-
这些 png 的宽度,高度,以像素为单位?它们应该自动缩放,但如果尺寸太大,可能存在一些 xamarin 错误。或者可能是 png 格式的问题。它们是“索引”格式吗?尝试另存为全彩 png。
标签: xamarin xamarin.forms xamarin.ios toolbar xamarin-forms-shell