How to load different information into same target page from different list view items

Apptacular Apps 386 Reputation points
2020-06-15T21:56:56.6+00:00

How can a particular XAML be opened from list view item click when the class name is different?

  • e.g. If I click the 2nd list item titled 'Sunflower', I want the 'DetailPage.xaml' to open where I'll dynamically add TabView items in the future.
  • I want to do the same with the other list items where the same DetailPage will be opened but different information would be added.

DetailPage class

    public sealed partial class DetailPage : Page
    {
        public DetailPage()
        {
            this.InitializeComponent();
        }
    }

DetailPage.xaml

 <Page [...]>
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="Auto" />
             <RowDefinition Height="*" />
         </Grid.RowDefinitions>
         <StackPanel Grid.Row="0">
             <TextBlock x:Uid="TitleText" />
         </StackPanel>
         <controls:TabView  Grid.Row="1" x:Name="MyTabs">

         </controls:TabView>
     </Grid>
 </Page>

MainPage class

    public sealed partial class MainPage: Page
    {
        public List<ListItemFlower> listItemFlowers;

        public MainPage()
        {
            this.InitializeComponent();

            listItemFlowers= ItemManagerFlowers.GetListItems();
        }

        private void ListFlower_ItemClick(object sender, ItemClickEventArgs e)
        {
            var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();

            ListItemFloweritem = (ListItemFlower)e.ClickedItem;

            if (item.Name == resourceLoader.GetString("Sunflower/Text"))
            {
                Frame.Navigate(typeof(FlowerPage)); 
            }
        }
    }
Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Fay Wang - MSFT 5,196 Reputation points
    2020-06-17T06:00:34.333+00:00

    Hello,

    Welcome to Microsoft Q&A!

    I want to do the same with the other list items where the same DetailPage will be opened but different information would be added.

    The Navigate() method has three parameters, the first one is the page you want to navigate to, the second one is the information you want to pass to the next page and the third one is the animated transition. So you can add the information you want to pass to the DetailPage into the Navigate() method and then subsrcibe the OnNavigatedTo() event in your DetailPage to receive the parameter. For example:

    MainPage.xaml.cs:

    if (item.Name == resourceLoader.GetString("Sunflower/Text"))  
    {  
        Frame.Navigate(typeof(DetailPage), "Your information");  
    }  
    

    DetailPage.xaml.cs:

    protected override void OnNavigatedTo(NavigationEventArgs e)  
    {  
        base.OnNavigatedTo(e);  
        string myInformation = e.Parameter as string;  
    }  
    
    0 comments No comments