Use the parameters passing from shell to content page

I have a problem of reading the parameters get by the shell to the content page.

I have registered the route and pass my parameters from shell to content page like this
await Shell.Current.GoToAsync($"location?code={loc}");

I get the data in my content page like this
[QueryProperty("LocationCode", "code")]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
private string lc;
public string LocationCode { get {return lc; } set { lc = Uri.UnescapeDataString(value); } }

var check = LocationCode//////// At here I cant get the value of my Location Code.

Any guides on how to fix this or any better ways to get the parameters from the shell?

Best Answer

  • ColeXColeX Xamurai
    Accepted Answer

    Do you call var check = LocationCode in page constructor ? The setter method is called after page constructor method , move your code into OnAppearing method .

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    This is the recommended way to receive data , which better way do you want ?

  • wlchoy96wlchoy96 Member ✭✭

    How if I am not using any view model..I cant directly use the data from Uri.UnescapeDataString(value)?

  • ColeXColeX Member, Xamarin Team Xamurai

    Why viewModel ? We define the property in pages.

    [QueryProperty("Name", "name")] would find the value we set in routes according to QueryId , and execute setter method of the property , so we can get the value .

    This is the only way (Get value by Property).

  • wlchoy96wlchoy96 Member ✭✭

    ![](https://us.v-cdn.net/5019960/uploads/editor/zx/k52t3t7ul2aq.png ""

    However I follow the same way but I cant get the value.

  • wlchoy96wlchoy96 Member ✭✭

    I cant get my location code

  • ColeXColeX Member, Xamarin Team Xamurai
    Accepted Answer

    Do you call var check = LocationCode in page constructor ? The setter method is called after page constructor method , move your code into OnAppearing method .

  • wlchoy96wlchoy96 Member ✭✭

    Now only i the setter method is called after constructor method..thank you very much

Sign In or Register to comment.