MAUI标签页在从另一页调用时崩溃。

huangapple go评论61阅读模式
英文:

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"

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;ContentPage xmlns=&quot;http://schemas.microsoft.com/dotnet/2021/maui&quot;
         xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;
          x:Class=&quot;TabbedMaui.MainPage&quot;
             xmlns:local=&quot;clr-namespace:TabbedMaui&quot; 
      &gt;
&lt;Button
    Text=&quot;Go&quot; Clicked=&quot;Button_Clicked&quot;&gt;&lt;/Button&gt;
ed&lt;/ContentPage&gt;

The second page is shown in the code block

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;TabbedPage xmlns=&quot;http://schemas.microsoft.com/dotnet/2021/maui&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;
             x:Class=&quot;TabbedMaui.SecondPage&quot;
             xmlns:local=&quot;clr-namespace:TabbedMaui&quot; 
        x:DataType=&quot;local:SecondPage&quot;
             Title=&quot;Some title&quot; BackgroundColor=&quot;blue&quot;&gt;
&lt;ContentPage Title=&quot;Page 1&quot; BackgroundColor=&quot;Red&quot;&gt;
    &lt;VerticalStackLayout &gt;
        &lt;Label Text=&quot;Hello&quot;&gt;&lt;/Label&gt;
    &lt;/VerticalStackLayout&gt;
             &lt;/ContentPage&gt;
&lt;ContentPage Title=&quot;Page 2&quot; BackgroundColor=&quot;Yellow&quot;&gt;&lt;/ContentPage&gt;
&lt;ContentPage Title=&quot;Page 3&quot;&gt;&lt;/ContentPage&gt;
&lt;/TabbedPage&gt;

答案1

得分: 1

这个问题可以在这里复现。而且这是一个已知的问题,可以在下面的链接中进行跟踪,您可以在那里跟进。

https://github.com/dotnet/maui/issues/7615

目前,您不能将TabbedPageMAUI 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.

huangapple
  • 本文由 发表于 2023年6月1日 12:51:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378747.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定