title: How can I get the parent container, e.g. PhoneApplicationPage, in Windows Phone?
body: <p>I need to call a method in my MainPage.xaml.cs class when an event is handled in a child control. Calling <code>this.Parent</code> doesn't work, because it only returns the first DependencyObject in the tree, and I can't get the <code>PhoneApplicationPage</code> from that</p>
  
  <p>I have the following layout in my <code>PhoneApplicationPage</code>:</p>
  
  <pre><code>&lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="AUTO"/&gt;
          &lt;RowDefinition Height="*"/&gt;
          &lt;RowDefinition Height="AUTO"/&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;Grid Height="85" VerticalAlignment="Top" Grid.Row="0"&gt;&lt;/Grid&gt;
  
      &lt;Grid Grid.Row="1" Name="gridContent" /&gt;
  
      &lt;ug:UniformGrid Rows="1" Columns="5" Height="85" VerticalAlignment="Bottom" Grid.Row="2"&gt;
          &lt;tabs:TabItem Name="tabOverview" TabItemText="OVERVIEW" TabItemImage="overview_64.png" /&gt;
          &lt;tabs:TabItem Name="tabLogs" TabItemText="LOGS" TabItemImage="log_64.png"/&gt;           
      &lt;/ug:UniformGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>with the following code:</p>
  
  <pre><code>public partial class MainPage : PhoneApplicationPage
  {
      public MainPage()
      {
          InitializeComponent();
  
          gridContent.Children.Add(new OverviewUserControl());
      }
  
      public void UpdateContent(UserControl control)
      {
          // I need to call this method from the TabItem Tap event
          gridContent.Children.Clear();
          gridContent.Children.Add(control);
      }
  }
  </code></pre>
  
  <p>When a tap event occurs, I need to replace the content of <code>gridContent</code> with whatever corresponds to the user's tap. this is how I handle the tap event:</p>
  
  <pre><code>private void TabItem_Tap(object sender, System.Windows.Input.GestureEventArgs e)
  {
  
      // var parent = this.Parent; //&lt;-- this doesn't get the PhoneApplicationPage
  
      var ti = sender as TabItem;
      if (ti != null)
      {
          string tab = "";
          switch (ti.Name)
          {
              case "tabOverview":
                  // I need a reference to MainPage here to call
                  // MainPage.UpdateContent(new LogsUserControl())
                  break;
              case "tabLogs":
                  // I need a reference to MainPage here to call
                  // MainPage.UpdateContent(new OverviewUserControl())
                  break;
          }
  
      }
  }
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>So the question is how can I call a method in <code>MainPage</code> from <code>TabItem_Tap</code>?</p>