如何在Xamarin中从一个页面到另一个页面保存数据?

时间:2018-01-25 10:20:43

标签: c# xamarin xamarin.forms

我将一个页面分成多个屏幕并且无法弄清楚如何绑定每个屏幕上的数据,这样如果你回到屏幕然后再回来,你就不会失去用户输入的内容。

1 个答案:

答案 0 :(得分:2)

使用SettingsPlugin(https://github.com/jamesmontemagno/SettingsPlugin

wroManagerFactory

用法:

        <plugin>
            <groupId>ro.isdc.wro4j</groupId>
            <artifactId>wro4j-maven-plugin</artifactId>
            <version>1.8.0</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
            <!-- Google Closure Compiler -->
            <!-- http://www.gzfs020.com/using-google-closure-compiler-with-wro4j-maven-plugin.html -->
            <configuration>
                <contextFolder>${basedir}/src/main</contextFolder>
                <wroFile>${basedir}/src/main/config/wro.xml</wroFile>
                <destinationFolder>${project.build.directory}/${project.build.finalName}/min</destinationFolder>
                <!--
                <wroManagerFactory>ro.isdc.wro.extensions.manager.standalone.GoogleStandaloneManagerFactory</wroManagerFactory>
                -->
                <wroManagerFactory>com.example.package.wro.CustomWroManagerFactory</wroManagerFactory>
            </configuration>
        </plugin>

或获取价值:using Xamarin.Forms; using Plugin.Settings; using Plugin.Settings.Abstractions; namespace MyNamespace { public static class PropertyStorage { private const string KeyMyPropertyX = "myPropertyX"; public static string MyPropertyX { get { return AppSettings.GetValueOrDefault(nameof(MyPropertyX), string.Empty, KeyMyPropertyX); } set { AppSettings.AddOrUpdateValue(nameof(MyPropertyX), value, KeyMyPropertyX); } } private static ISettings AppSettings { get { return CrossSettings.Current; } } } }