在页面之间传递数据Xamarin Shell导航
我有一个Xamarin Forms应用程序,其表单在多个页面上分开,我想将对象数据传递到下一个或上一页。我正在使用Xamarin Shell导航。我可以使用什么方法或设置来实现这一目标?
我知道的选项以及我对它们的感知问题:
- json串起对象并将其作为参数传递。
这似乎是不正确的,因为数据正在来回转换。
- 将对象的每个属性作为单个参数传递。
长时间缠绕着许多特性,并且不灵活地变化。
- 将数据存储到SQLITE数据库中。
我不想在表中存储不完整的记录并使用当前的sqliteasyncconnection,我不相信我可以从同一类中创建2个表。
I have a Xamarin forms app with a form split across multiple pages, I want to pass the object data to the next or previous page. I am navigating using the Xamarin Shell. What method or setup can I use to achieve this?
The options I am aware of and my perceived issues with them:
- JSON string the object and pass it as a parameter.
This seems incorrect as the data is being converted back and forth.
- Pass every property of the object as an individual parameter.
Massively long winded with many properties and inflexible to change.
- Store the data to a SQLite database.
I would not want to store an incomplete record in the table and using the current SQLiteAsyncConnection, I don't believe I can have 2 tables created from the same class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以使用查询属性属性传递数据。
可以通过为每个查询参数的QueryPropertyAttribute装饰接收类,可以收到导航数据。
有关更多信息,请检查: https://learn.microsoft.com/en-us/xamarin/xamarin/xamarin-forms/app-fundamentals/shell/navigation#process-process-process-navigation-data-using-query-query-query-property-attributes 。
此外,另一种方法是在应用程序中创建全局可变,您可以在应用程序中访问此可变性。
例如:
1。Create class
myVariables.cs
,并为您的模型添加静态变量(例如myViewModel
):myviewmodel.cs
2.您可以在应用程序中修改或访问您的变量:
Yes,you can pass data using query property attributes .
Navigation data can be received by decorating the receiving class with a QueryPropertyAttribute for each query parameter.
For more, check:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#process-navigation-data-using-query-property-attributes .
In addition,another method is to create a global varible in your app, them you can access this varible in your app.
For example:
1.create class
MyVariables.cs
and add static variable for your model (e.g.MyViewModel
) :MyViewModel.cs
2.You can modify or access your variable in your app:
不幸的是,我们现在只能传递简单的数据。此功能将来会添加: https://github.com/xamarin/ xamarin.forms/desiss/6848 您可以创建多个QueryPropertyAttribute来访问其他数据: https://learn.microsoft.com/en-us/xamarin/xamarin/xamarin-forms/app-fundamentals/shell/navigation#pass-pass-pass-pass-pass-dass-data 另一种方法是将对象转换为JSON字符串,例如:
var jSonstr = jsonconvert.serializeObject(model);
然后在导航时通过它。
Unfortunately, we could only pass simple data now. And this feature will be added in the future: https://github.com/xamarin/Xamarin.Forms/issues/6848 You can create multiple QueryPropertyAttribute to access different data: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#pass-data Another approach is to convert the object to a JSON string like:
var jsonStr = JsonConvert.SerializeObject(model);
Then pass it when navigating.