question

ApptacularApps-8305 avatar image
0 Votes"
ApptacularApps-8305 asked ·

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

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)); 
             }
         }
     }




windows-uwpwindows-uwp-xaml
· 4
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you mean when you click item from MainPage and navigate to the FlowerPage, you want to open the DetailPage instead? In addition, may I know how did you create the DetailPage.xaml and FlowerPage class? Are they single xaml file and class file? Do you want the FlowerPage as the code-behind for DetailPage?

0 Votes 0 ·

Question has been updated for clearer context.

0 Votes 0 ·

Do you mean when you open the DetailPage.xaml page, you want to pass different information to the DetailPage?

0 Votes 0 ·
Show more comments

1 Answer

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered ·

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;
 }


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.