title: C# can't access WPF object in websocket?
body: <p>I assume this is a scoping issue... but I'm not that good with C# so I need help...</p>
  
  <p>Firstly, I have a tabControl in my XAML:</p>
  
  <pre><code>&lt;TabControl x:Name="tabControl" x:FieldModifier="public" /&gt;
  </code></pre>
  
  <p>Items in this TabControl are added dynamically in code. Each tab has a "content" field which is added based on a bunch of UserControls. IE: <code>tab.Content = new TextFields(this);</code></p>
  
  <p>Somewhere else in my code, I can do the following to echo out the names of all my tabs:</p>
  
  <pre><code>foreach (TabItem item in tabControl.Items)
  {
      MessageBox.Show(item.Name.ToString());
  }
  </code></pre>
  
  <p>So far this all works great. However, now I am trying to access my tabs through WebSockets. Basically, I want the end user to be able to type in a tab name, and if that tab exists, execute a function in that tab's UserControl such as <code>getTabData</code>.</p>
  
  <p>Just for basic testing, I moved the above <code>foreach</code> into my WebSocket:</p>
  
  <pre><code>var sockets = new List&lt;Fleck.IWebSocketConnection&gt;();
  var websock = new Fleck.WebSocketServer("ws://0.0.0.0:58341");
  websock.Start(socket =&gt;
  {
      socket.OnOpen = () =&gt; sockets.Add(socket);
      socket.OnClose = () =&gt; sockets.Remove(socket);
      socket.OnMessage = message =&gt;
      {
          sockets.ToList().ForEach(s =&gt; s.Send("Echo: " + message));
          foreach (TabItem item in tabControl.Items)
          {
              MessageBox.Show(item.Name.ToString());
          }
      };
  });
  </code></pre>
  
  <p>Unfortunately, the MessageBox function just seems to outright fail as the name of each tab seems to be null. It knows the number of tabs in the tab control, but it can't seem to get the name of the tabs or the contents of the tabs. How can I fix this?</p>
  
  <p>The websocket is in MainWindow.cs, and the TabControl is in MainWindow.xaml</p>