title: Access controls from a normal class (.cs)
body: <p>I'm working on a project and need to access a label from a normal class.cs.<br>
  NOT from the MainWindow.xaml.cs!</p>
  
  <p><code>MainWindow.xaml</code>: contains a Label <code>lblTag</code>.</p>
  
  <p>Class.cs needs to execute:</p>
  
  <pre><code>lblTag.Content = "Content";
  </code></pre>
  
  <p>How can I realize it? </p>
  
  <p>I just end up with <strong><code>InvalidOperationExceptions</code></strong>.          </p>
  
  <p>Window1.xaml.cs:</p>
  
  <pre><code>public Window1()
  {
      InitializeComponent();
      [...]
  }
  
  [...]
  StreamElement se1;
  StreamElement se2;
  
  private void Window_Loaded(object sender, RoutedEventArgs e)
  {
      [...]
      se1 = new StreamElement(this);
      se2 = new StreamElement(this);
  
      [...]
  }
  
  [...]
  </code></pre>
  
  <p>StreamElement.cs:</p>
  
  <pre><code>[...]
  private Window1 _window;
  [...]
  
  public StreamElement(Window1 window)
  {
      _window = window;
  }
  
  [...]
  
  //metaSync is called, whenever the station (it's a sort of internet radio recorder)
  //changes the meta data
  public void metaSync(int handle, int channle, int data, IntPtr user)
  {
      [...]
  
      //Tags just gets the meta data from the file stream
      Tags t = new Tags(_url, _stream);
      t.getTags();
  
      //throws InvalidOperationException - Already used in another thread
      //_window.lblTag.Content = "Content" + t.title;
  }
  
  [...]
  </code></pre>