title: FindName returning null
body: <p>I'm writing a simple tic tac toe game for school. The assignment is in C++, but the teacher has given me permission to use C# and WPF as a challenge. I've gotten all the game logic finished and the form mostly complete, but I've run into a wall. I'm currently using a <code>Label</code> to indicate who's turn it is, and I want to change it when a player makes a valid move. According to <a href="https://rads.stackoverflow.com/amzn/click/com/0735619573" rel="nofollow noreferrer" rel="nofollow noreferrer">Applications = Code + Markup</a>, I should be able to use the <code>FindName</code> method of the <code>Window</code> class. However, it keeps returning <code>null</code>. Here's the code:</p>
  
  <pre><code>public TicTacToeGame()
  {
      Title = "TicTacToe";
      SizeToContent = SizeToContent.WidthAndHeight;
      ResizeMode = ResizeMode.NoResize;
  
      UniformGrid playingField = new UniformGrid();
      playingField.Width = 300;
      playingField.Height = 300;
      playingField.Margin = new Thickness(20);
  
      Label statusDisplay = new Label();
      statusDisplay.Content = "X goes first";
      statusDisplay.FontSize = 24;
      statusDisplay.Name = "StatusDisplay"; // This is the name of the control
      statusDisplay.HorizontalAlignment = HorizontalAlignment.Center;
      statusDisplay.Margin = new Thickness(20);
  
      StackPanel layout = new StackPanel();
      layout.Children.Add(playingField);
      layout.Children.Add(statusDisplay);
  
      Content = layout;
  
      for (int i = 0; i &lt; 9; i++)
      {
          Button currentButton = new Button();
          currentButton.Name = "Space" + i.ToString();
          currentButton.FontSize = 32;
          currentButton.Click += OnPlayLocationClick;
  
          playingField.Children.Add(currentButton);
      }
  
      game = new TicTacToe.GameCore();
  }
  
  void OnPlayLocationClick(object sender, RoutedEventArgs args)
  {
      Button clickedButton = args.Source as Button;
  
      int iButtonNumber = Int32.Parse(clickedButton.Name.Substring(5,1));
      int iXPosition = iButtonNumber % 3,
          iYPosition = iButtonNumber / 3;
  
      if (game.MoveIsValid(iXPosition, iYPosition) &amp;&amp; 
          game.Status() == TicTacToe.GameCore.GameStatus.StillGoing)
      {
          clickedButton.Content = 
              game.getCurrentPlayer() == TicTacToe.GameCore.Player.X ? "X" : "O";
          game.MakeMoveAndChangeTurns(iXPosition, iYPosition);
  
          // And this is where I'm getting it so I can use it.
          Label statusDisplay = FindName("StatusDisplay") as Label;
          statusDisplay.Content = "It is " +
              (game.getCurrentPlayer() == TicTacToe.GameCore.Player.X ? "X" : "O") +
              "'s turn";
      }
  }
  </code></pre>
  
  <p>What's going on here? I'm using the same name in both places, but <code>FindName</code> can't find it. I've tried using Snoop to see the hierarchy, but the form doesn't show up in the list of applications to choose from. I  searched on StackOverflow and found I <a href="https://stackoverflow.com/questions/1274943/window-findname-cant-find-border-element-that-ive-named-through-an-attached-pro/1275422#1275422">should be able to use VisualTreeHelper class</a>, but I don't understand how to use it.</p>
  
  <p>Any ideas?</p>