使用 Xamarin.Forms Shell 进行 ListView 导航
我正在尝试弄清楚如何使我的应用程序成为 Shell 应用程序。
这是我的 shell.xaml。
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Project.View"
x:Class="Project.AppShell">
<ShellContent Title=""
ContentTemplate="{DataTemplate views:MainPage}"/>
<ShellContent Title=""
ContentTemplate="{DataTemplate views:ListView}"
Route="StockListView"/>
</Shell>
我无法理解路由,我的目标是使路由从列表视图到另一个视图,如下所示。
MainView
ListView
ViewItem
我不清楚如何实现这一点,因为列表视图不是三个主要分层对象之一,至少对我来说并不明显。 https://learn.microsoft.com/ en-us/xamarin/xamarin-forms/app-fundamentals/shell/introduction 。我可以通过更改连接到列表视图的视图模型中的页面来使其工作。
App.Current.Mainpage = View
但感觉我把事情搞混了,应该可以以某种方式使用 Shell 路由,这可能吗?
I am trying to figure out how to make my application a Shell application.
This is my shell.xaml.
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Project.View"
x:Class="Project.AppShell">
<ShellContent Title=""
ContentTemplate="{DataTemplate views:MainPage}"/>
<ShellContent Title=""
ContentTemplate="{DataTemplate views:ListView}"
Route="StockListView"/>
</Shell>
I am having trouble to make sense of the routing, my goal is to make routing from the listview to another view, like below.
MainView
ListView
ViewItem
I don't find it clear how to implement this, since the listview is not one of the three main hierachical objects, at least not obvious for me.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/introduction
. I can get it to work by changing the page from my viewmodel that is connected to my listview.
App.Current.Mainpage = View
But it feels like I am mixing things up and that it should be possible to use Shell routing in some way, is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先需要注册路由,可以在xaml页面注册路由,也可以在后端代码中注册路由。
更多信息您可以参考:注册路线。
注册路由后,您可以使用
await Shell.Current.GoToAsync("//ListView/ViewItem");
代码优雅地进行调用。请注意多级别路由(路由层次结构)的使用。
路线导航的详细使用方法,可以查看:执行导航。
First you need to register the route, you can register the route in the xaml page or register the route in the back-end code.
For more information you can refer to: Register routes.
After registering the route you can use
await Shell.Current.GoToAsync("//ListView/ViewItem");
code to make the call elegantly.Please take care of the use of routes multiple levels(route hierarchy).
For the detailed usage of route navigation, you can check: Perform navigation.