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表单时添加导航向后箭头


基础教程推荐
猜你喜欢
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01