【发布时间】:2015-03-16 15:20:27
【问题描述】:
我的应用中有两个页面。第一个是 MainPage,第二个是 SettingsPage 我的设置页面中有一个文本框。我想保存这个文本框文本并发送到 MainPage。
这里是新的例子。现在它可以工作了,但我无法保存 SettingsPage 中的 textBox1.text 。当我浏览其他页面时,它正在清理。
public sealed partial class MainPage : Page
{
private NavigationHelper navigationHelper;
public MainPage()
{
this.InitializeComponent();
progRing.IsActive = true;
Window.Current.SizeChanged += Current_SizeChanged;
this.NavigationCacheMode = NavigationCacheMode.Required;
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
}
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
this.txtBoxNotification.Text = (string)e.NavigationParameter;
}
private void btnNotification_Click(object sender, RoutedEventArgs e)
{
webView.Navigate(new Uri("http://teknoseyir.com/u/" + txtBoxNotification ));
}
【问题讨论】:
-
每当您向前导航到一个新页面时,它都会创建一个新的页面实例,因此它不会存储它。如果您需要永久存储值,则需要考虑使用静态值,或创建视图模型来存储数据
标签: c# windows-phone-8.1