title: C# WPF - How to simply update UI from another class/thread
body: <p><em>I couldn't find a <strong>simple</strong> solution to this problem. That's why I'm asking.</em></p>
  
  <p>I have a WPF <strong>window</strong> like this:</p>
  
  <pre><code>&lt;Window x:Class="WPF_Test.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Width="640" Height="480"&gt;
  
      &lt;Button Name="xaml_button" Content="A Text."/&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And a MainWindow <strong>class</strong>:</p>
  
  <pre><code>using System.Windows;
  using System.Threading;
  
  namespace WPF_Test
  {
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
              xaml_button.Content = "Text changed on start.";
          }
      }
  
      private void xaml_button_Click()
      {
          Threading.t1.Start();
          UIControl.ChangeButtonName("Updated from another CLASS.");
      }
  }
  </code></pre>
  
  <p>The button's <code>Content</code> property <strong>successfully</strong> changed itself. But what I want to do, is to change the property in <strong>another</strong> class <em>or</em> thread. What I tried is this:</p>
  
  <pre><code>class UIControl
  {
      public static void ChangeButtonName(string text)
      {
          var window = new MainWindow();
          window.xaml_button.Content = text;
      }
  }
  </code></pre>
  
  <p>It obviously <strong>doesn't work</strong>, because the <code>public MainWindow()</code> changes the <code>Content</code> property back to the original one, and brings some issues along with it.</p>
  
  <p>Also I want to use this while <strong>multithreading</strong>. My simple threading class looks like this:</p>
  
  <pre><code>class Threading
  {
      public static Thread t1 = new Thread(t1_data);
  
      static void t1_data()
      {
          Thread.Sleep(2000);
          UIControl.ChangeButtonName("Updated from another THREAD.");
      }
  }
  </code></pre>