LongListSelector not working (not navigating to other pages)

牧云@^-^@ 提交于 2019-12-13 04:05:50

问题


I have implemented a LongListSelector for my Windows Phone 7 app. However when I tap an item it doesn't navigate to the desired page. Does anyone know why and how this can be fixed? Below is my code. Each page has it's own uri and I want to navigate to different pages.

All help would be very much appreciated.

Many thanks

Code:

Imports System.Linq
Imports Microsoft.Phone.Controls

Partial Public Class Victoria_line
    Inherits PhoneApplicationPage
    Public Sub New()

        InitializeComponent()
        Dim source As New List(Of JumpDemo)()

        source.Add(New JumpDemo() With { _
            .Name = "Blackhorse Road", _
            .FareZone = "Fare zone 3", _
            .GroupBy = "b", _
            .Link = "/Lines and Stations/Victoria/Blackhorse_Road_(Victoria).xaml" _
        })
        source.Add(New JumpDemo() With { _
            .Name = "Warren Street", _
            .FareZone = "Fare zone 1", _
            .GroupBy = "w", _
            .Link = "/Lines and Stations/Victoria/Warren_Street_(Victoria).xaml" _
        })


        Dim MygroupBy = From jumpdemo In source _
                      Group jumpdemo By jumpdemo.GroupBy Into c = Group _
                      Order By GroupBy _
                      Select New  _
                      Group(Of JumpDemo)(GroupBy, c)

        Me.Victoria_line.ItemsSource = MygroupBy

    End Sub

    Private Sub Victoria_line_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        If Victoria_line.SelectedItem = Nothing Then
            Return
        End If

        Dim addressString As String = "/StationPage.xaml"
        Dim pageUri As Uri = New Uri(addressString, UriKind.Relative)
        NavigationService.Navigate(pageUri)

        ' Reset selected item to -1 (no selection)
        Victoria_line.SelectedItem = Nothing
    End Sub

End Class

Public Class Group(Of T)
    Implements IEnumerable(Of T)
    Public Sub New(name As String, items As IEnumerable(Of T))
        Me.Title = name
        Me.Items = New List(Of T)(items)
    End Sub
    Public Overrides Function Equals(obj As Object) As Boolean
        Dim that As Group(Of T) = TryCast(obj, Group(Of T))
        Return (that IsNot Nothing) AndAlso (Me.Title.Equals(that.Title))
    End Function
    Public Property Title() As String
        Get
            Return m_Title
        End Get
        Set(value As String)
            m_Title = value
        End Set
    End Property
    Private m_Title As String
    Public Property Items() As IList(Of T)
        Get
            Return m_Items
        End Get
        Set(value As IList(Of T))
            m_Items = value
        End Set
    End Property
    Private m_Items As IList(Of T)
    Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
        Return Me.Items.GetEnumerator()
    End Function
    Private Function System_Collections_IEnumerable_GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return Me.Items.GetEnumerator()
    End Function
End Class


Public Class Victoria
    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set(value As String)
            m_Name = value
        End Set
    End Property
    Private m_Name As String

    Public Property FareZone() As String
        Get
            Return m_FareZone
        End Get
        Set(value As String)
            m_FareZone = value
        End Set
    End Property
    Private m_FareZone As String

    Public Property GroupBy() As String
        Get
            Return m_GroupBy
        End Get
        Set(value As String)
            m_GroupBy = value
        End Set
    End Property
    Private m_GroupBy As String

    Public Property Link() As Uri
        Get
            Return m_Link
        End Get
        Set(value As Uri)
            m_Link = value
        End Set
    End Property
    Private m_Link As Uri
End Class

回答1:


If what you are trying to achieve is navigate to another page when you tap on an item you should just register for the Tap event inside your Item DataTemplate and in the event handler do something like this:

Private Sub Item_Tap(sender As Object, e As GestureEventArgs)
    Dim element As FrameworkElement = TryCast(sender, FrameworkElement)
    Dim item As JumpDemo = TryCast(element.DataContext, JumpDemo)

    Dim addressString As String = item.Link
    Dim pageUri As Uri = New Uri(addressString, UriKind.Relative)
    NavigationService.Navigate(pageUri)

End Sub


来源:https://stackoverflow.com/questions/19299801/longlistselector-not-working-not-navigating-to-other-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!