【问题标题】:Displaying number of items according to parameters passed xaml windows phone根据传递给xaml windows phone的参数显示项目数
【发布时间】:2014-01-22 20:49:17
【问题描述】:

好的,我有一个 MainPage.xaml

这会将参数传递给 NextPage.xaml,如下所示 NextPage.xaml?count=10

现在我想在一个长列表选择器上显示 10 个项目,这个数字取决于传递的参数我该怎么做,我可以动态绑定数据吗?

【问题讨论】:

  • 您自己几乎解决了您的问题 - 只需获取您已通过导航到的号码,然后根据此号码填写您的 LLS 列表(observablecollection?)。你能再展示一些你有问题的代码吗?

标签: c# xaml visual-studio-2012 data-binding windows-phone-8


【解决方案1】:

你可以这样获取导航参数:

if (NavigationContext.QueryString.ContainsKey("count"))
        {
            var countString = NavigationContext.QueryString["count"];
            var count = Int32.Parse(countString);
            // Create list
            for(int i = 0; i < count; i++) 
            {
                 MyLLSList.Add(new Item());
            }
        }

其中 MyLLSList 是 ViewModel 中的一个属性,您可以将其绑定为 LLS ItemSource。

希望这会有所帮助。

【讨论】:

  • 是的,它确实帮助了我。我将这些项目添加到长列表选择器中。我第一次创建了一个列表并向其中添加了项目。没用,这很好!我现在觉得有点傻 :D 再次感谢
【解决方案2】:
NavigationService.Navigate(new Uri("/Pagina2.xaml?count=10", UriKind.Relative));

你做什么。如果你想传递一个包含整数 10 的变量:

int getInteger= 10;
NavigationService.Navigate(new Uri("/Pagina2.xaml?count="+getInteger, UriKind.Relative));

【讨论】:

  • 我已经传递了变量,只是在导航页面上的长列表选择器上绑定了一些问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多