[英]Xamarin forms read file on start app and save on close
I want to save config file.我想保存配置文件。 My save and load function works correctly when I call it from the button.
当我从按钮调用它时,我的保存和加载功能正常工作。 But I want to improve it and save my file and load when app is closing /opening.
但我想改进它并在应用程序关闭/打开时保存我的文件和加载。 These methods are on MainPage.xaml.cs.
这些方法位于 MainPage.xaml.cs 上。
protected override void OnStart()
{
MainPage mainPage = new MainPage();
mainPage.Load_File();
}
protected override void OnSleep()
{
MainPage mainPage = new MainPage();
mainPage.Save_File();
}
When I created it like this save and load not working.当我像这样创建它时,保存和加载不起作用。
when you create your MainPage
, save a reference to it so you can reuse it later创建
MainPage
,请保存对它的引用,以便以后可以重用
MainPage main;
public App ()
{
InitializeComponent ();
MainPage = main = new MainPage();
}
protected override void OnStart()
{
main.Load_File();
}
protected override void OnSleep()
{
main.Save_File();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.