【问题标题】:Passing LINQ element as parameter to another .xaml wp7将 LINQ 元素作为参数传递给另一个 .xaml wp7
【发布时间】:2013-01-09 10:03:41
【问题描述】:

是否可以将 LINQ 查询的结果作为参数发送到 WP7 中的另一个 .xaml 文件。 如果是,那么您能否通过示例进行解释。 提前致谢

这是我的代码

XDocument xml = XDocument.Load("VideoContent.xml");
var content = from query in xml.Descendants("Video") where (string)query.Element("Clip") == parameter 
              select new Video() { File = (string)query.Element("File") }

现在我需要使用 NAvigationService 将 File 中的字符串传递给另一个 .xaml。

P.S 我对 WP7 和 LINQ 很陌生

【问题讨论】:

  • LINQ 查询或 LINQ 查询的结果?你的 LINQ 的格式是什么?]
  • 是 LINQ 的结果。 XDocument xml = XDocument.Load("VideoContent.xml"); var content = from query in xml.Descendants("Video") where (string)query.Element("Clip") == parameter select new Video() { File = (string)query.Element("File") };现在我需要使用 NAvigationService 将 File 中的字符串传递给另一个 .xaml。 P.S 我对 WP7 和 LINQ 很陌生

标签: windows-phone-7


【解决方案1】:

如果要传递字符串值,可以将其作为导航参数传递。

NavigationService.Navigate(new Uri("/NewPageName.xaml?file="+content.First().File, UriKind.Relative));

然后在新页面的 OnNavigatedTo 处理程序中,像这样获取“文件”字符串值

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        string file; //declare this before the page constructor

        NavigationContext.QueryString.TryGetValue("file", out file);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-14
    • 2013-10-13
    • 1970-01-01
    • 2018-08-20
    • 2012-03-08
    • 1970-01-01
    • 2019-12-11
    • 2023-01-18
    相关资源
    最近更新 更多