WP8 LongListSelector - 导航到不同的页面 [英] WP8 LongListSelector - Navigating to different pages

查看:16
本文介绍了WP8 LongListSelector - 导航到不同的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近为我的 Windows Phone 8 应用程序创建了一个 LongListSelector.然而,我现在想要实现的是当用户点击一个项目时导航到另一个页面,但我不知道我的代码中放了什么,而且我也不是 100% 我应该为每个人插入我的 uri页.有谁知道我如何实现这一目标?

如果有人能帮我解决这个问题,我将不胜感激.

非常感谢.

部分公共课站_Chooser继承PhoneApplicationPage公共子新建()初始化组件()Dim source As New List(Of Glasgow)()source.Add(新格拉斯哥(桥街"))source.Add(新格拉斯哥(布坎南街"))source.Add(新格拉斯哥(塞斯诺克"))source.Add(New Glasgow("Cowcaddens"))source.Add(新格拉斯哥(戈文"))source.Add(New Glasgow("Hillhead"))source.Add(新格拉斯哥(Ibrox"))source.Add(New Glasgow("Kelvinbridge"))source.Add(New Glasgow("Kelvinhall"))source.Add(新格拉斯哥(金宁公园"))source.Add(新格拉斯哥(帕特里克"))source.Add(New Glasgow("Shields Road"))source.Add(新格拉斯哥(圣以诺"))source.Add(New Glasgow("St George's Cross"))source.Add(新格拉斯哥(西街"))Dim DataSource As List(Of AlphaKeyGroup(Of Glasgow)) = AlphaKeyGroup(Of Glasgow).CreateGroups(source, System.Threading.Thread.CurrentThread.CurrentUICulture, Function(s As Glasgow)返程站结束函数,真)GlasgowSubway.ItemsSource = 数据源结束子公共课格拉斯哥公共属性 Station() 作为字符串得到返回 m_Station结束获取设置(值作为字符串)m_Station = 值结束集最终财产私有 m_Station 作为字符串Public Sub New(station As String)Me.Station = 车站结束子结束类结束类

解决方案

有一些方法可以做到这一点.this SO question中显示了其中之一,也许不是最好或最漂亮的方法,而是一个非常简单的方法.><块引用>

SelectionChanged附加事件处理程序,在处理程序中添加导航到新页面的命令,设置SelectedItem = null

我假设目标页面对于选择的任何项目都是相同的页面,只显示不同的内容/数据.您需要在 Uri 参数中传递所选项目的签名,以使目标页面能够相应地显示信息.例如:

NavigationService.Navigate(New Uri("/nextpage.xaml?selectedStation=" & selectedItem.Station, UriKind.Relative))

更新:

正如您澄清的那样,每个项目的目标页面都不同,我之前的回答仍然有效.只需要修改后面的部分,不使用Uri参数.所以这就是我的想法.在 Glasgow 类中添加另一个属性,例如 StationId.初始化时:

//第二个参数是StationId值source.Add(New Glasgow("Bridge Street", "BridgeStreet"))

然后用模式StationId.xaml命名每个页面,所以Bridge Street的页面应该是BridgeStreet.xaml.这样,在 SelectionChanged 事件处理程序中,您可以导航到相应的页面,而无需使用 Select Case selectedItem.Station ...:

NavigationService.Navigate(New Uri(selectedItem.StationId & ".xaml", UriKind.Relative))

注意:模型中有多个属性(在本例中为 StationStationId)需要您指定要在 LongListSelector 中显示的属性代码>.如果您还不知道,请查看此链接以了解如何操作.

I have recently created a LongListSelector for my Windows Phone 8 app. However what I want to achieve now is to navigate to another page when the user taps on an item but I don't know what put in my code and also I'm not 100% as to where I should insert my uri's for each individual page. Does anyone know how I can achieve this?

I would be grateful if anyone could help me with this matter.

Many thanks.

Partial Public Class Station_Chooser
    Inherits PhoneApplicationPage

    Public Sub New()
        InitializeComponent()

        Dim source As New List(Of Glasgow)()
        source.Add(New Glasgow("Bridge Street"))
        source.Add(New Glasgow("Buchanan Street"))
        source.Add(New Glasgow("Cessnock"))
        source.Add(New Glasgow("Cowcaddens"))
        source.Add(New Glasgow("Govan"))
        source.Add(New Glasgow("Hillhead"))
        source.Add(New Glasgow("Ibrox"))
        source.Add(New Glasgow("Kelvinbridge"))
        source.Add(New Glasgow("Kelvinhall"))
        source.Add(New Glasgow("Kinning Park"))
        source.Add(New Glasgow("Patrick"))
        source.Add(New Glasgow("Shields Road"))
        source.Add(New Glasgow("St Enoch"))
        source.Add(New Glasgow("St George's Cross"))
        source.Add(New Glasgow("West Street"))


        Dim DataSource As List(Of AlphaKeyGroup(Of Glasgow)) = AlphaKeyGroup(Of Glasgow).CreateGroups(source, System.Threading.Thread.CurrentThread.CurrentUICulture, Function(s As Glasgow)
                                                                                                                                                                          Return s.Station
                                                                                                                                                                      End Function, True)
        GlasgowSubway.ItemsSource = DataSource

    End Sub

    Public Class Glasgow
        Public Property Station() As String
            Get
                Return m_Station
            End Get
            Set(value As String)
                m_Station = value
            End Set
        End Property
        Private m_Station As String

        Public Sub New(station As String)
            Me.Station = station
        End Sub
    End Class

End Class

解决方案

There are some ways to do that. One of them shown in this SO question, maybe not the best or the most beautiful way but a very simple one.

Attach event handler for SelectionChanged, add command for navigating to new page in the handler, set SelectedItem = null

I assumed that the destination page is same page for any item selected, only different content/data displayed. You need to pass selected item's signature in the Uri parameter to enable destination page to display information accordingly. For example :

NavigationService.Navigate(New Uri("/nextpage.xaml?selectedStation=" & selectedItem.Station, UriKind.Relative))

UPDATE :

As you clarified that destination page will be different for each item, my previous answer still valid. Only the later part need to be modified, not using Uri parameter. So this is what I think. Add another property in Glasgow class, say it StationId. Upon initialization :

//the second parameter is StationId value
source.Add(New Glasgow("Bridge Street", "BridgeStreet"))

Then name each page with pattern StationId.xaml, so page for Bridge Street should be BridgeStreet.xaml. With that, in SelectionChanged event handler you can navigate to corresponding page without using Select Case selectedItem.Station ...:

NavigationService.Navigate(New Uri(selectedItem.StationId & ".xaml", UriKind.Relative))

Note : Having more then one properties in the model (Station and StationId in this case) require you to specify which property to display in LongListSelector. Check this link to know how, if you don't know yet.

这篇关于WP8 LongListSelector - 导航到不同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆