0

CurrentItem does not work on iOS but it does work on Android, I am using xamarin. This is my code:

Shell.Current.CurrentItem = new MyPageTest();

Launch this exception:

system.NullReferenceExcepion
Object reference not set to an instance of an object.

Is there any way to change the CurrentItem?

deHaar
  • 17,687
  • 10
  • 38
  • 51
  • Can you please add more code about where you call `Shell.Current.CurrentItem = new MyPageTest();`? In my understanding, `Shell.Current.CurrentItem` point to currently selected `Xamarin.Forms.ShellItem` or `Xamarin.Forms.FlyoutItem` and it should be a existing page instead of a new page. Have a look at my answer [here](https://stackoverflow.com/questions/59248713/setting-a-default-page-in-the-xamarin-forms-shell-menu/59259763#59259763) for more information. – nevermore Dec 24 '19 at 01:56
  • I'm calling from a view or page that doesn't have shell. That is all my code is just a button to change the CurrentItem. – Juan carlos Dec 26 '19 at 13:23
  • Can you please share a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) to us? I can't reproduce the problem on my side. – nevermore Dec 27 '19 at 01:28

1 Answers1

0

Solved, I deleted Xamarin.forms from my project and Installed again from nuget. and this code Shell.Current.CurrentItem = new MyPageTest(); is correct, but doesn't get the correct result I change by await Shell.Current.GoToAsync("//myshellapproot/shellcontentview");