0

我已經爲我的Windows Phone 7應用程序實現了一個LongListSelector。但是,當我點擊一個項目時,它不會導航到所需的頁面。有誰知道爲什麼以及如何解決這個問題?以下是我的代碼。每個頁面都有它自己的uri,我想導航到不同的頁面。LongListSelector不工作(不導航到其他頁面)

所有的幫助將非常感激。

非常感謝

代碼:

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 

回答

0

如果你正在努力實現的時候,你就應該只註冊您的項目的DataTemplate內的點擊事件中的項目挖掘被導航到另一個頁面什麼,在事件處理程序中做這樣的事情:

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 
相關問題