Search code examples
c#vb.netxamlwindows-store-apps

GridView ItemClick navigate to another page and show details about the clicked item Windows store app


i have a GridView with item from a list of person list, how can i show details of the clicked item in the next page?

in the main page i have used this code

Private Sub itemGridView_ItemClick(sender As Object, e As ItemClickEventArgs) Handles itemGridView.ItemClick
    Me.Frame.Navigate(GetType(BlankPage1), e.ClickedItem)
End Sub

and i have used this in the next page

Private Sub NavigationHelper_LoadState(sender As Object, e As Common.LoadStateEventArgs)
    Dim n As Person = TryCast(e.NavigationParameter, Person)
    txt.Text = n.Name
End Sub

Solution

  • I fixed it by changing my code

    Private Sub itemGridView_ItemClick(sender As Object, e As ItemClickEventArgs) Handles itemGridView.ItemClick
        Dim person As Person = DirectCast(e.ClickedItem, Person)
        Me.Frame.Navigate(GetType(BlankPage1), person)
    End Sub
    

    in the next page

    Private Sub NavigationHelper_LoadState(sender As Object, e As Common.LoadStateEventArgs)
        Dim person As Person = DirectCast(e.NavigationParameter, Person)
        Me.DefaultViewModel("Details") = person
    End Sub
    

    And in my xaml file i added this

    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"