title: Xamarin Forms check is page is Modal
body: <p>So basically I'm try to to find out if a page was pushed modally.</p>
  <p>Here is the code I have for my extension method:</p>
  <pre><code>public static bool IsModal(this Page page)
  {
      return page.Navigation.ModalStack.Any(p =&gt; page == p);
  }
  </code></pre>
  <p>The issue is; <code>p</code> never equals <code>page</code> due to the fact <code>p</code> changes to NavigationPage during runtime although intellisense reports it as a type of Page at compile time.</p>
  <p>I've tried casting <code>p</code> to a Page but the type does not change at runtime and intellisense just moans that the cast is redundant.</p>
  <p>I call this extension by using <code>CurrentPage.IsModal</code> in my View Model. <code>CurrentPage</code> is a type of Page at compile time but then changes to NavigationPage at runtime.</p>
  <p>The confusing thing is that during debugging, <code>p</code> has properties such as <code>CurrentPage</code> and <code>RootPage</code> which show in the debugger, but these are not accessible by using <code>p.CurrentPage</code> as the compiler complains they don't exist !?! I was going to try an compare these but I can't access them but can view them in the debugger.</p>