英文:
MAUI Tabbed Page crashes when it is called from another page
问题
以下是您要翻译的内容:
简单示例
主页(这是一个简单的内容页,带有一个按钮)
第二页(当按下按钮时显示的选项卡页面)
该代码在Windows下运行正常,但在Android启动期间崩溃并显示“未找到片段视图ID”
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TabbedMaui.MainPage"
xmlns:local="clr-namespace:TabbedMaui"
>
<Button
Text="Go" Clicked="Button_Clicked"></Button>
</ContentPage>
第二页显示在以下代码块中:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TabbedMaui.SecondPage"
xmlns:local="clr-namespace:TabbedMaui"
x:DataType="local:SecondPage"
Title="Some title" BackgroundColor="blue">
<ContentPage Title="Page 1" BackgroundColor="Red">
<VerticalStackLayout >
<Label Text="Hello"></Label>
</VerticalStackLayout>
</ContentPage>
<ContentPage Title="Page 2" BackgroundColor="Yellow"></ContentPage>
<ContentPage Title="Page 3"></ContentPage>
</TabbedPage>
英文:
Simple example
Main Page (which is a simple content page with a button)
Second Page (which is the tabbed page displayed when the button is pressed)
The code works under Windows, but on Android crashes during startup with "fragment viewid not found"
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TabbedMaui.MainPage"
xmlns:local="clr-namespace:TabbedMaui"
>
<Button
Text="Go" Clicked="Button_Clicked"></Button>
ed</ContentPage>
The second page is shown in the code block
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TabbedMaui.SecondPage"
xmlns:local="clr-namespace:TabbedMaui"
x:DataType="local:SecondPage"
Title="Some title" BackgroundColor="blue">
<ContentPage Title="Page 1" BackgroundColor="Red">
<VerticalStackLayout >
<Label Text="Hello"></Label>
</VerticalStackLayout>
</ContentPage>
<ContentPage Title="Page 2" BackgroundColor="Yellow"></ContentPage>
<ContentPage Title="Page 3"></ContentPage>
</TabbedPage>
答案1
得分: 1
这个问题可以在这里复现。而且这是一个已知的问题,可以在下面的链接中进行跟踪,您可以在那里跟进。
https://github.com/dotnet/maui/issues/7615
目前,您不能将TabbedPage与MAUI Shell
一起使用,正如官方文档明确说明的那样:
TabbedPage与.NET MAUI Shell应用程序不兼容,如果您尝试在Shell应用程序中使用TabbedPage,将会引发异常。
作为替代解决方案,您可以尝试将App.MainPage
设置为TabbedPage
以解决此问题。
英文:
This issue can be reproduced here. And it is a known issue that being tracked in the link below, you can follow up there.
https://github.com/dotnet/maui/issues/7615
Currently, you cannot mix TabbedPage together with MAUI Shell
as the official docs states clearly below:
> TabbedPage is incompatible with .NET MAUI Shell apps, and an
> exception will be thrown if you attempt to use TabbedPage in a Shell
> app.
As an alternative workaround, you may be able to set the App.MainPage
to a TabbedPage
to get it resolved.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论