-2

I am trying to test if the current page of my application is the CardsTabPage like this:

_page.CurrentPage is Japanese.CardsTabPage

However it always returns false even though when I use the debugger it seems like it should read true. Here's what I see when I hover over CurrentPage:

enter image description here

Does anyone have any idea what might be wrong and why this:

enter image description here

is not returning true?

I also tried this but it doesn't work:

enter image description here

Alan2
  • 23,493
  • 79
  • 256
  • 450

1 Answers1

1

You need to access _page.CurrentPage.CurrentPage, but you can't do that directly because the compile-time type of _page.CurrentPage is just Page. You need to first cast that to NavigationPage, then use the CurrentPage property of that.

If your compiler supports pattern matching, you can do that as:

if (_page.CurrentPage is NavigationPage np && np.CurrentPage is Japanese.CardsTabPage)

Otherwise you'd need something like:

if (_page.CurrentPage is NavigationPage &&
    ((NavigationPage) _page.CurrentPage).CurrentPage is Japanese.CardsTabPage)
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194