title: Get WPF resource from code?
body: <p>What is the simplest way to get a WPF resource from code?</p>
  
  <p>I need to disable a text box in a WPF form if a checkbox in the same window is checked. I have wired the checkbox to an event handler in code-behind. The event handler disables the checkbox and changes its background to a light gray, to indicate that the control is disabled:</p>
  
  <pre><code>private void OnCheckBoxChecked(object sender, RoutedEventArgs e)
  {
      MyTextBox.IsEnabled = false;
      MyTextBox.Background = (Brush)FindResource("DisabledControlBackgroundBrush");
  }
  </code></pre>
  
  <p>The disabled control background color is defined as a resource in a resource dictionary that is imported into the WPF window. I tested the resource by setting the textbox background in XAML, and the resource works fine. </p>
  
  <p>I also know the event handler is working, because it disables the text box when the checkbox is clicked. </p>
  
  <p>My problem is that the event handler isn't changing the Background property as it should. I suspect that there is a problem with my call to FindResource, but I am not getting an exception, and the Output window has nothing on it.</p>
  
  <p>So, how do I get this resource from code and apply it to my text box? Thanks for your help.</p>