Passing Parameters using QueryParameter in MAUI

Jassim Al Rahma 1,616 Reputation points
2023-01-04T16:30:11.733+00:00

Hi,

I am trying to pass PackageId and PackageName using QuerParameter in MAUI project but nothing is showing.

Hee is my sample:

https://github.com/jrahma/QueryPropertySample/tree/main/QueryPropertySample

Kindly help..

Thanks,
Jassim

Developer technologies .NET .NET MAUI
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-01-05T07:04:24.757+00:00

    Hello,

    if you have multiple parameters like PackageID and PackageName, does this. mean you have to create another method for every parameter?

    You can create an object with PackageID and PackageName attributes. then send this object by QueryProperty.

    For example, I create a Package class.

       public class Package  
       {  
           public string packageId { get; set; }  
          public string packageName { get; set; }  
       }  
    

    Then I send this object by Dictionary in the GoTapGestureRecognizer_Tapped method.

       async void  GoTapGestureRecognizer_Tapped(object sender, EventArgs e)  
           {  
                  Label lbl = (Label)sender;  
              
                  Package package=  new Package() { packageId = lbl.Text, packageName = "yourpageName" };  
         
                  var navigationParameter = new Dictionary<string, object> { { "MyPackage", package } };  
         
                  await Shell.Current.GoToAsync($"MyPage2", navigationParameter);  
          }  
    

    You can get this object in the MyPage2's background code. Please notice I change the property in QueryProperty and MyPage2.cs like the following code.

       [QueryProperty(nameof(MyPackage), "MyPackage")]  
       public partial class MyPage2 : ContentPage  
       {  
           public Package MyPackage  
           {  
               set  
               {  
                   ShowMessage(value);  
               }  
           }  
           public MyPage2()  
           {  
               InitializeComponent();  
               
           }  
         
          public async void ShowMessage(Package package)  
           {  
               var id = package.packageId;  
               var name = package.packageName;  
              await DisplayAlert("Query", id+ name, "Ok");  
           }  
       }  
    

    You can refer to this document about Pass data

    Here is a document about passing and processing multiple items of data in shell with QueryProperty.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.