LongListSelector不工作(不导航到其他页面)

时间:2013-10-10 15:18:39

标签: vb.net xaml windows-phone-7 silverlight-toolkit longlistselector

我为我的Windows Phone 7应用程序实现了一个LongListSelector。但是,当我点按某个项目时,它不会导航到所需的页面。有谁知道为什么以及如何解决这个问题?以下是我的代码。每个页面都有自己的uri,我想导航到不同的页面。

非常感谢所有帮助。

非常感谢

代码:

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 个答案:

答案 0 :(得分:0)

如果你想要实现的是当你点击一个项目时导航到另一个页面,你应该在Item DataTemplate中注册Tap事件,并在事件处理程序中执行以下操作:

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