Passing data using Shell and remember it

Jassim Al Rahma 1,521 Reputation points
2022-08-17T23:16:04.127+00:00

Hi,

I am trying to pass data from Page-A to Page-B using the following:

In Page-A:

await Shell.Current.GoToAsync($"MemberDetails?MyMember=1000", true);  

and In Page-B:

[QueryProperty("Member", "MyMember")]  

then:

private string member;  
public string Member  
{  
    set { member = value; }  
    get { return member; }  
}  

but when I try to display the value in Page-B using:

DisplayAlert("member", member, "Ok");  

It does not show any value.

Please see the attached sample.

https://www.bluefile.app/temp/ShellNavigation.zip

Kindly help..

Thanks,
Jassim

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,869 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,471 Reputation points Microsoft Vendor
    2022-08-19T02:47:53.643+00:00

    Hello,

    No, there is no need to set another variable.

    Your issue is caused by that you set LabelParameter.Text = member; in your page constructor method.

    Therefore, your program will call LabelParameter.Text = member; at first, then call member = value; secondly.

    You could use the following ways to deal with the issue:

    Method 1:

    You could call LabelParameter.Text = member; in the setter method:

       set   
       {   
           member = value;   
           LabelParameter.Text = member;  
       }  
    

    Method 2:

    You could call LabelParameter.Text = member; in the OnAppearing method:

       protected override void OnAppearing()   
       {  
           base.OnAppearing();  
           LabelParameter.Text = member;  
       }  
    

    Best Regards,

    Alec Liu.


    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.