【问题标题】:passing values from one form to another in Windows Phone 7在 Windows Phone 7 中将值从一种形式传递到另一种形式
【发布时间】:2011-03-07 05:08:30
【问题描述】:

我对如何在 Windows Phone 7 中将值从一种形式传递到另一种形式存在疑问,我是 silverlight 概念的新手,不知道如何在形式之间传递值。我已经尝试了很多搜索。但一切都是徒劳的。

如果有人知道,请帮助我。

谢谢 BHAVIK GOYAL

【问题讨论】:

标签: wpf silverlight windows-phone-7


【解决方案1】:

这可能会有所帮助:Passing values to Windows Phone 7 pages: URI paremeters and QueryString

要在导航到另一个页面时传递参数,您必须在 Uri 路径中指定它们。您只能使用“?”字符和“&”作为分隔符以字符串格式传递参数(与大多数网站相同)。在以下示例中,我将两个参数传递给 AnotherPage.xaml。请记住存储在 NavigationContext 中的参数。

string parameter1Value = "test1";
string parameter2Value = "test2";
NavigationService.Navigate(
    new Uri(string.Format("/AnotherPage.xaml?myparameter1={0}&myparameter2={1}",
        parameter1Value, parameter2Value),
        UriKind.Relative));

现在我们需要在 AnotherPage.xaml 页面上获取这些参数。为此,您需要重写 OnNavigatedTo 方法并从 NavigationContext 获取这些参数及其值。

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    string myparameter1Value = null;
    string myparameter2Value = null;

    NavigationContext.QueryString.TryGetValue("myparameter1", out myparameter1Value);
    NavigationContext.QueryString.TryGetValue("myparameter2", out myparameter2Value);
}

【讨论】:

  • 谢谢eibhrum...这真的帮助了我...我添加了对您的回答有用的代码。
【解决方案2】:

这里详细解释了如何在 Windows Phone 7 中的页面之间传递数据。它还包括所有 4 个过程的示例代码

http://nishantcop.blogspot.com/2011/08/passing-data-between-pages-in-windows.html

【讨论】:

    【解决方案3】:

    这是一个使用查询字符串在两个页面之间传递值的简单项目。 http://dl.dropbox.com/u/129101/Panorama_querystring.zip

    【讨论】:

      猜你喜欢
      • 2015-06-23
      • 2015-06-06
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多