title: WPF, updating status bar in main window from within UserControl
body: <p>I have a <code>StatusBar</code> in my main window, and I also have a copy of a <code>UserControl</code> in my main window.  From within event handlers in my <code>UserControl</code>, I want to update the <code>StatusBar</code> in the main window.  What would be the best way of doing this?  Is there a way of getting access to the instance of my main window from <code>object sender</code> or <code>RoutedEventArgs e</code> in an event handler in <code>UserControl</code>?</p>
  
  <p><strong>Edit:</strong>  thanks to <a href="https://stackoverflow.com/questions/3460531/wpf-updating-status-bar-in-main-window-from-within-usercontrol/3460784#3460784">lukas's answer</a> and <a href="http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-custom-event-handlers" rel="nofollow noreferrer">this tutorial</a>, I came up with the following solution:</p>
  
  <p>Added to my <code>UserControl</code>:</p>
  
  <pre><code>public delegate void UpdateStatusBarEventHandler(string message);
  
  public event UpdateStatusBarEventHandler UpdateStatusBar;
  </code></pre>
  
  <p>Added to my main window's constructor, after <code>InitializeComponent</code>:</p>
  
  <pre><code>uct_requiredFields.UpdateStatusBar += updateStatusBar;
  </code></pre>
  
  <p>And I added this method to my main window:</p>
  
  <pre><code>private void updateStatusBar(string message)
  {
      sti_mainStatus.Content = message;
  }
  </code></pre>
  
  <p>Then, from within my <code>UserControl</code>, I can do the following to update the status bar:</p>
  
  <pre><code>if (null != UpdateStatusBar)
  {
      UpdateStatusBar("woot, message");
  }
  </code></pre>