title: x:Name does not exist in the current context, but its parent does
body: <p>I want to update some text on a flyout. However, when I try to set its value in the code behind I get the error "The name 'dateChosen' does not exist in the current context".</p>
  
  <p>Code behind:</p>
  
  <pre><code>private void updateDateBinding()
  {
      lstMenus.Visibility = Visibility.Visible;
      dateChosen.Text = ""; // &lt;-- Error here
  }
  </code></pre>
  
  <p>Xaml code:</p>
  
  <pre><code>    &lt;ListView x:Name="lstMenus"&gt;
  
  &lt;!-- ...other code... --&gt;
  
          &lt;TextBox x:Name="dateChosen" IsReadOnly="True"
                   Text="{Binding getDateChosen, Mode=TwoWay}"/&gt;
  
  &lt;!-- ...other code... --&gt;
  
      &lt;/ListView&gt;
  </code></pre>
  
  <p>Originally I was only going to use the PropertyChanged event to update 'dateChosen' but it did not update when calling that event. So I've decided to set the value explicitly instead, only to find this issue.</p>
  
  <p>What confuses me is that 'lstMenus' can be altered exactly as I would expect. How can my ListView exist, but not the TextBox inside of it?</p>
  
  <p>-</p>
  
  <p>PS: I've cut most of superfluous code from this (Height/Width, Background, Alignment, etcetera) but I feel I should mention that the TextBox in question is pretty deeply nested in this chunk of code. The full inheritance is:</p>
  
  <p>ListView(lstMenus) - ListView.ItemTemplate - DataTemplate - StackPanel - Grid - Grid - AppBarButton - AppBarButton.Flyout - Flyout - Grid - Grid - TextBox(dateChosen)</p>
  
  <p>I've tried setting the 'x:Name' property for some of the intervening tags but always get the same "not in current context" issue when I try reaching them from the code behind.</p>