【发布时间】:2022-01-15 07:53:36
【问题描述】:
我正在使用 Xamarin.Forms - Shell 功能。 我需要从一个选项卡(根)导航到另一个选项卡(第二级)。 该示例包含三个页面,为简单起见,我将其命名为 Page1、Page2 和 Page3。 Page1 和 Page2 是 App Shell 的主要选项卡,Page 3 是 Page1 的第二层(堆栈)。
下一个代码是 AppShell.xaml 的一部分:
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<ShellContent Route="page1" Title="Page1" ContentTemplate="{DataTemplate local:Page1}" />
<ShellContent Route="page2" Title="Page2" ContentTemplate="{DataTemplate local:Page2}" />
</FlyoutItem>
AppShell.cs 中的构造函数是
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute(nameof(Page3), typeof(Page3));
}
第 1 页和第 3 页非常相似,只是代表两个页面。接下来是Page1.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestGoTo.Views.Page1"
Title="Page1" BackgroundColor="LightGreen">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Page1"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
Page2.xaml 包含一个用于调用 GoToAsync 函数的按钮
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestGoTo.Views.Page2"
Title="Page2" BackgroundColor="LightYellow">
<ContentPage.Content>
<StackLayout>
<Label Text="Page2" HorizontalOptions="CenterAndExpand" />
<Button Text="GoTo" Clicked="Button_Clicked"></Button>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Page2.cs - 按钮操作是
private async void Button_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync($"//page1/{nameof(Page3)}");
}
问题:
当您转到 Page2 并单击按钮时,预期的行为是在第 1 页的选项卡下显示第 3 页,但您仍然在选项卡/page2 中。如果您(手动)转到第 1 页,您将看到第 3 页的堆栈。因此,第 3 页位于正确的位置(已加载),但您没有看到它,因为您仍然在第 2 页中。
此问题仅在 iOS 中出现,Android 正常工作。
这里有什么问题? Xamarin.Forms (Shell for iOS) 中是否存在错误?
感谢您的帮助。
【问题讨论】:
标签: c# ios shell xamarin.forms