add navigation back arrow when using ShellContent xamarin forms(使用ShellContent Xamarin表单时添加导航向后箭头)
本文介绍了使用ShellContent Xamarin表单时添加导航向后箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,当我们使用ShellContent
导航到仪表板页面时,导航栏中没有后退箭头?
您知道如何导航到仪表板页面并可以返回到上一页吗?
<Shell ..>
<ShellContent x:Name="home"
IsVisible={Binding IsVisibleHome}
Route="main"
ContentTemplate="{DataTemplate home:Dashboard}" />
<ShellContent Route="test"
ContentTemplate="{DataTemplate home:Dashboard2}" />
</Shell>
推荐答案
没有简单的内置方法可以做到这一点。
这里有一种方法,它将路由更改为不同的路由,该路由不会作为Shell的(ShellContent)子级进行访问。这基于AboutPage
,该AboutPage
是Xamarin窗体的";弹出&q;项目模板的一部分。将AboutPage
替换为您的页面,并将路由替换为您的路由。
public partial class AppShell : Xamarin.Forms.Shell
{
public AppShell()
{
InitializeComponent();
// Define a route that isn't a child of Shell.
Routing.RegisterRoute("about2", typeof(AboutPage));
}
protected override void OnNavigating(ShellNavigatingEventArgs args)
{
base.OnNavigating(args);
if (args.Current != null) {
// This line hopefully avoids interfering with Pop, if AboutPage links to another page.
if (args.Source == ShellNavigationSource.ShellItemChanged) {
// Replace "//AboutPage" with the route to your page.
if (args.Target.Location.OriginalString == "//AboutPage") {
// Cancel the original route.
args.Cancel();
Device.BeginInvokeOnMainThread(() => {
// Go there by a route that isn't a child of Shell.
Shell.Current.GoToAsync("about2");
});
}
}
}
}
}
结果:以前的shell位置被推送到NAV堆栈。AboutPage
出现,导航栏左上角有一个后退箭头。
换句话说,AboutPage
现在的行为与以下任何其他页面一样:
- 未在Shell层次结构中定义-不是Shell的子级。
- 并且定义了路由。
诀窍是我们定义了第二条路由,它将我们带到同一个页面。然后我们截取原始路由,并将其替换为此备用路由。
这篇关于使用ShellContent Xamarin表单时添加导航向后箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:使用ShellContent Xamarin表单时添加导航向后箭头


猜你喜欢
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01