C# 如何将文本框文本数据传输到其他页面?Windows Phone 8.1

C# 如何将文本框文本数据传输到其他页面?Windows Phone 8.1,c#,windows-phone-8.1,C#,Windows Phone 8.1,我的应用程序中有两个页面。第一个是主页,第二个是设置页面在我的设置页面中有一个文本框。我想保存此文本框文本并发送到主页 这里是一个新的例子。现在它可以工作了,但是我无法保存设置页面中的textBox1.text。当我浏览其他页面时,它正在清理 public sealed partial class MainPage : Page { private NavigationHelper navigationHelper; public MainPage() {

我的应用程序中有两个页面。第一个是主页,第二个是设置页面在我的设置页面中有一个文本框。我想保存此文本框文本并发送到主页

这里是一个新的例子。现在它可以工作了,但是我无法保存设置页面中的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 ));
    }

在WP8中,在页面之间发送导航参数的标准方法是使用

NavigationService.Navigate(new Uri("/MainPage.xaml?text=" + textBox1.Text, UriKind.Relative));
然后在导航到的页面上的OnNavigatedTo()方法上检查参数

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string settingsText = NavigationContext.QueryString["text"];
}
对于Windows Phone 8.1,您不再使用URI进行导航。方法是使用:

this.Frame.Navigate(typeof(MainPage), textBox1.Text);
然后,在您导航到的页面的loadstate上,您可以使用以下方法获取数据:

private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
    string text = e.NavigationParameter as string;
}  

希望这有帮助。

在WP8中,在页面之间发送导航参数的标准方法是使用

NavigationService.Navigate(new Uri("/MainPage.xaml?text=" + textBox1.Text, UriKind.Relative));
然后在导航到的页面上的OnNavigatedTo()方法上检查参数

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string settingsText = NavigationContext.QueryString["text"];
}
对于Windows Phone 8.1,您不再使用URI进行导航。方法是使用:

this.Frame.Navigate(typeof(MainPage), textBox1.Text);
然后,在您导航到的页面的loadstate上,您可以使用以下方法获取数据:

private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
    string text = e.NavigationParameter as string;
}  

希望这有帮助。

您也可以通过使用PhoneApplicationService来实现这一点。设置一个这样的值

string str = textBox.Text;
PhoneApplicationService.Current.State["TextBoxValue"] = str;
textblock.Text = PhoneApplicationService.Current.State["TextBoxValue"] as String;
现在,您可以随时调用该值,并使用它作为键值。得到这样的值

string str = textBox.Text;
PhoneApplicationService.Current.State["TextBoxValue"] = str;
textblock.Text = PhoneApplicationService.Current.State["TextBoxValue"] as String;

您也可以通过使用PhoneApplicationService来实现这一点。设置一个这样的值

string str = textBox.Text;
PhoneApplicationService.Current.State["TextBoxValue"] = str;
textblock.Text = PhoneApplicationService.Current.State["TextBoxValue"] as String;
现在,您可以随时调用该值,并使用它作为键值。得到这样的值

string str = textBox.Text;
PhoneApplicationService.Current.State["TextBoxValue"] = str;
textblock.Text = PhoneApplicationService.Current.State["TextBoxValue"] as String;

在Windows Phone 8.1中,可以将值作为Frame.Navigate方法的参数进行传输

例如,您希望传递您类型的值:

Frame.Navigate(typeof(TargetPage), yourValue); 
并在目标页面中获取它:

protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
    var value = navigationParameter as yourType;
}
protected async override void LoadState(对象导航参数,字典页面状态)
{
var value=navigationParameter作为您的类型;
}

该值是您希望获得的值。

在Windows Phone 8.1中,您可以将值作为Frame.Navigate方法的参数进行传输

例如,您希望传递您类型的值:

Frame.Navigate(typeof(TargetPage), yourValue); 
并在目标页面中获取它:

protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
    var value = navigationParameter as yourType;
}
protected async override void LoadState(对象导航参数,字典页面状态)
{
var value=navigationParameter作为您的类型;
}

值就是您想要得到的值。

我使用的最简单的方法是在主页中声明一个公共静态类,这样您就可以在应用程序页面的任何位置使用相同的类方法,如下所示:

public static class MyClass
{
    public static string MyString = null;
}
PhoneApp.MainPage.MyClass.MyString = TextBoxInSettings.Text;
TextBoxInMainPage.Text = MyClass.MyString;
然后,您可以从设置页面的文本框中为其指定一个值,如下所示:

public static class MyClass
{
    public static string MyString = null;
}
PhoneApp.MainPage.MyClass.MyString = TextBoxInSettings.Text;
TextBoxInMainPage.Text = MyClass.MyString;
然后将该值返回主页中的另一个文本框,如下所示:

public static class MyClass
{
    public static string MyString = null;
}
PhoneApp.MainPage.MyClass.MyString = TextBoxInSettings.Text;
TextBoxInMainPage.Text = MyClass.MyString;

我使用的最简单的方法是在主页中声明一个公共静态类,这样您就可以在应用程序页面的任何位置使用相同的类方法,如下所示:

public static class MyClass
{
    public static string MyString = null;
}
PhoneApp.MainPage.MyClass.MyString = TextBoxInSettings.Text;
TextBoxInMainPage.Text = MyClass.MyString;
然后,您可以从设置页面的文本框中为其指定一个值,如下所示:

public static class MyClass
{
    public static string MyString = null;
}
PhoneApp.MainPage.MyClass.MyString = TextBoxInSettings.Text;
TextBoxInMainPage.Text = MyClass.MyString;
然后将该值返回主页中的另一个文本框,如下所示:

public static class MyClass
{
    public static string MyString = null;
}
PhoneApp.MainPage.MyClass.MyString = TextBoxInSettings.Text;
TextBoxInMainPage.Text = MyClass.MyString;

它在导航服务处显示红线。Error=在当前上下文中不存在。您是为WP8或WP8.1创建的吗?我是为WP8.1创建的。多亏了你,我很亲近。现在LoadStateEventArgs给出红线。我会把密码寄出去。它可以用于其他页面,但我在主页(我的应用程序的第一页,您知道standart的第一页是自动创建的)上缺少一些内容。LoadStateEventArgs位于YOURAPPNAME.Common命名空间中。如果还没有,请尝试添加“usingyourappname.Common;”在页面顶部显示您的使用。它在导航服务处显示红线。Error=在当前上下文中不存在。您是为WP8或WP8.1创建的吗?我是为WP8.1创建的。多亏了你,我很亲近。现在LoadStateEventArgs给出红线。我会把密码寄出去。它可以用于其他页面,但我在主页(我的应用程序的第一页,您知道standart的第一页是自动创建的)上缺少一些内容。LoadStateEventArgs位于YOURAPPNAME.Common命名空间中。如果还没有,请尝试添加“usingyourappname.Common;”当你向前导航到一个新页面时,它会创建一个新的页面实例,所以它不会存储它。如果您需要永久性地存储值,则需要研究使用静态值,或创建viewmodels来存储数据,无论何时向前导航到新页面,它都会创建页面的新实例,因此不会存储它。如果需要永久存储值,则需要研究使用静态值,或创建viewmodels来存储数据