【问题标题】:passing information between pages in windows phone 8在 windows phone 8 中的页面之间传递信息
【发布时间】:2016-07-24 22:05:16
【问题描述】:

我需要在 Windows Phone 8 的三个页面之间传递一个简单的 texbox。我一直在四处寻找,但没有找到,我试过这个,'https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx' 我在这个方法中有问题:

private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)

{

    string name = e.NavigationParameter as string;

    if (!string.IsNullOrWhiteSpace(name))
    {
        tb1.Text = "Hello, " + name;
    }
    else
    {
        tb1.Text = "Name is required.  Go back and enter a name.";
    }
}

我找不到 LoadStateEventArgs e,缺少 using 指令或程序集引用。

【问题讨论】:

  • 你用这个方法有什么问题?你有什么例外吗?您需要更具体地了解您的问题。
  • 当我写方法时,Visual Studio 说我找不到命名空间名称 LoadStateEventArgs e
  • 您是在编写 Windows 8 还是 Windows 8.1 应用程序? Visual Studio 2012 还是 2013??
  • Windows 8.1,视觉工作室 2013
  • 嘿!我想我想帮助你!你想将文本框中的值传递到多个页面还是什么?

标签: c# wpf visual-studio-2013 windows-phone-8.1 code-behind


【解决方案1】:

如果我正确理解了您的问题,您希望将值存储在 3 个不同页面的文本框中。对吧?

检查并告诉我

   // let's assume that you have a simple class:
    public class PassedData
    {
       public string Name { get; set; } //for textBox1
       public string Name1 { get; set; } //for textBox2
       public string Name3 { get; set; } //for textBox3
       public string Name4 { get; set; } //for textBox4
       public string Name5 { get; set; } //for textBox5
       public int Value { get; set; }
    }

//create object of the class like this and asign values to the properties

PassedData abc=new PassedData();
abc.Name=TextBox1.Text;
abc.Name2=TextBox2.Text;
abc.Name3=TextBox3.Text;
abc.Value=TextBox4.Text.ToString();
    // then you navigate like this:
   Frame.Navigate(typeof(Page2), abc);

    // and in target Page you retrive the information:
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        PassedData data = e.Parameter as PassedData;
    }

【讨论】:

  • 有一个问题,我不能应用于 windows phone 8.1,但适用于 windows phone 7
  • 我找不到导航服务
  • 对 windows phone 8.1 使用 Frame.Navigate()
  • frame.navigate 有效,问题在于传递信息
  • ok 你想传递什么信息?假设您的 textxbox1.text 数据以名称 Value 存储在字符串变量中,像这样将其传递给其他页面... Frame.Navigate(typeof(Page2.Xaml),Value);
【解决方案2】:

我不会过多地关注您传递的数据,而是关注作为应用程序骨干的数据模型。应该有一个包含您要存储的文本内容的数据模型类。这个类的实例应该“生存”任何页面,所以如果你有一个页面写入这个属性,那么你可以有另一个页面显示这个字段的值。您还应该考虑为每个页面创建一个视图模型,作为在模型和页面之间传递属性值的胶水代码,如果您有类型转换、数据验证、必填字段等,也可以提供帮助。

【讨论】:

  • 坦克,让我试试
猜你喜欢
  • 2013-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-16
  • 1970-01-01
相关资源
最近更新 更多