我为具有选项卡式布局的依赖项 xamarin.essentials\1.5.3.2 和 xamarin.forms\4.8.0.1451 (默认值)的 android 创建了跨平台项目。然后我使用 MasterDetailPage 模板添加了 TestMasterDetailPage。AppShell.xaml 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MasterDetailTest.Views"
Title="MasterDetailTest"
x:Class="MasterDetailTest.AppShell">
<TabBar>
<ShellContent Title="About" Icon="icon_about.png" Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
<ShellContent Title="Browse" Icon="icon_feed.png" ContentTemplate="{DataTemplate local:ItemsPage}" />
<ShellContent Title="TestMasterDetailPage" Route="TestMasterDetailPage" ContentTemplate="{DataTemplate local:TestMasterDetailPage}" />
</TabBar>
</Shell>
我删除了一些未使用的代码并在 TabBar 中添加了第三个选项卡。启动它并按下新选项卡时,外部代码出现错误:System.InvalidCastException: 'Specified cast is not valid.'
我发现这个问题看起来相同,但它是 2yo,我不确定当时是否使用 shell 作为模板。此外,如前所述,崩溃发生在外部代码的某处。