Windows phone 保存数据并填充元素以返回到Universal App Windows中的页面

Windows phone 保存数据并填充元素以返回到Universal App Windows中的页面,windows-phone,windows-phone-8.1,windows-8.1,win-universal-app,Windows Phone,Windows Phone 8.1,Windows 8.1,Win Universal App,我有一个关于通用应用程序(Windows和Windows Phone 8.1)页面间导航的问题。我有一个包含各种元素(滑块、组合框等)的页面,当我转到下一个页面并返回时,值会返回到初始状态,而不是我所做的更改。有谁能告诉我,是否有可能将保留在元素中的值返回到页面?如果可能的话,有人能告诉我怎么做吗?谢谢。您只需在页面构造函数中将NavigationCacheMode属性的值更改为Required或Enabled即可。您需要逐页执行此操作 public MainPage() { this.

我有一个关于通用应用程序(Windows和Windows Phone 8.1)页面间导航的问题。我有一个包含各种元素(滑块、组合框等)的页面,当我转到下一个页面并返回时,值会返回到初始状态,而不是我所做的更改。有谁能告诉我,是否有可能将保留在元素中的值返回到页面?如果可能的话,有人能告诉我怎么做吗?谢谢。

您只需在页面构造函数中将
NavigationCacheMode
属性的值更改为
Required
Enabled
即可。您需要逐页执行此操作

public MainPage()
{
    this.InitializeComponent();
    this.NavigationCacheMode = NavigationCacheMode.Required;
}

不同之处在于
已启用
它会将页面缓存到缓存大小,由
Frame
CacheSize
属性控制。对于
Required
它将缓存页面,而不管缓存大小。

最好的方法是在xaml中按页面进行缓存,如下所示

<Page
    x:Class="Universal.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Universal"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    NavigationCacheMode="Required">

希望这能有所帮助。

非常感谢你的朋友。我可能会像在App.xaml.cs?@vtncgustavo中按下HardwareBackButton_时一样,在一般情况下这样做。不幸的是,您需要在页面级别这样做。
public class CachedPage : Page
{
    public CachedPage() : base()
    {
        this.NavigationCacheMode = NavigationCacheMode.Required;
    }
}