简体   繁体   English

在 Xamarin.Forms 中推送现有页面

[英]Pushing an Existing Page in Xamarin.Forms

I'm making a text based game on Xamarin.Forms.我正在 Xamarin.Forms 上制作基于文本的游戏。 currently my main page has a "Start Game" Button.目前我的主页有一个“开始游戏”按钮。 and I'm using NavigationPage to go to the game page, like so:我正在使用 NavigationPage 转到游戏页面,如下所示:

  Navigation.PushAsync(new GamePage());

I'm Trying to add a "Resume Game" Button that will go the game page but with all the data that exists in it.我正在尝试添加一个“继续游戏”按钮,该按钮将进入游戏页面,但包含其中存在的所有数据。 basically i want it so that when you exit the "Game Page" the data doesn't wipe.基本上我想要它,以便当您退出“游戏页面”时数据不会擦除。 and you can resume it at anytime.您可以随时恢复它。 I'm wondering if this at all possible as the data on the Game Page is to much to just call it all when invoking the page.我想知道这是否可能,因为在调用页面时,游戏页面上的数据太多了。

You can define game data on GamePage's constructor.您可以在 GamePage 的构造函数上定义游戏数据。 And you can easily pass your data to this GamePage via constructor.您可以通过构造函数轻松地将数据传递到此 GamePage。 For Example :例如 :

Navigation.PushAsync(new GamePage(gameData));

and your data does not wipe.并且您的数据不会擦除。

There is no way to load an existing page directly into Xamarin.无法将现有页面直接加载到 Xamarin 中。 You will need to think about another way to store the game state.您将需要考虑另一种存储游戏状态的方法。

The easiest way is to use a text file (xml, json...) that you will load and pass as parameter to your page.最简单的方法是使用文本文件(xml、json...),您将加载该文件并将其作为参数传递到您的页面。

Don't forget to save the state in the different events of the App Life Cycle to avoid data loss.不要忘记保存 App Life Cycle 的不同事件中的状态,以避免数据丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM