0

Я применил LongListSelector для моего приложения Windows Phone 7. Однако, когда я нажимаю элемент, он не перемещается на нужную страницу. Кто-нибудь знает, почему и как это можно исправить? Ниже мой код. На каждой странице есть собственный 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

Если то, что вы пытаетесь достичь будет перемещаться на другую страницу при нажатии на элемент вы должны просто зарегистрироваться на событие Tap внутри вашего пункта 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 
Смежные вопросы