title: How can I bind a background color in WPF/XAML?
body: <p>What do I have to change to the following code so that the background is red, neither of the 2 ways I tried worked:</p>
  
  <p><a href="https://i.stack.imgur.com/Fdeku.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Fdeku.png" alt="alt text"></a><br>
  <sub>(source: <a href="http://www.deviantsart.com/upload/1okq25l.png" rel="noreferrer">deviantsart.com</a>)</sub>  </p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="TestBackground88238.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300"&gt;
      &lt;StackPanel&gt;
  
          &lt;TextBlock Text="{Binding Message}" Background="{Binding Background}"/&gt;
  
          &lt;TextBlock Text="{Binding Message}"&gt;
              &lt;TextBlock.Background&gt;
                  &lt;SolidColorBrush Color="{Binding Background}"/&gt;
              &lt;/TextBlock.Background&gt;
          &lt;/TextBlock&gt;
  
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Code Behind:</strong></p>
  
  <pre><code>using System.Windows;
  using System.ComponentModel;
  
  namespace TestBackground88238
  {
      public partial class Window1 : Window, INotifyPropertyChanged
      {
  
          #region ViewModelProperty: Background
          private string _background;
          public string Background
          {
              get
              {
                  return _background;
              }
  
              set
              {
                  _background = value;
                  OnPropertyChanged("Background");
              }
          }
          #endregion
  
          #region ViewModelProperty: Message
          private string _message;
          public string Message
          {
              get
              {
                  return _message;
              }
  
              set
              {
                  _message = value;
                  OnPropertyChanged("Message");
              }
          }
          #endregion
  
  
  
          public Window1()
          {
              InitializeComponent();
              DataContext = this;
  
              Background = "Red";
              Message = "This is the title, the background should be " + Background + ".";
  
          }
  
          #region INotifiedProperty Block
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected void OnPropertyChanged(string propertyName)
          {
              PropertyChangedEventHandler handler = PropertyChanged;
  
              if (handler != null)
              {
                  handler(this, new PropertyChangedEventArgs(propertyName));
              }
          }
          #endregion
  
      }
  }
  </code></pre>
  
  <h1>Update 1:</h1>
  
  <p>I tried Aviad's answer which didn't seem to work. I can do this manually with x:Name as shown here but I want to be able to bind the color to a INotifyPropertyChanged property, how can I do this?</p>
  
  <p><a href="https://i.stack.imgur.com/M30pO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/M30pO.png" alt="alt text"></a><br>
  <sub>(source: <a href="http://www.deviantsart.com/upload/7tp48m.png" rel="noreferrer">deviantsart.com</a>)</sub>  </p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="TestBackground88238.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300"&gt;
      &lt;StackPanel&gt;
  
          &lt;TextBlock Text="{Binding Message}" Background="{Binding Background}"/&gt;
  
          &lt;TextBlock x:Name="Message2" Text="This one is manually orange."/&gt;
  
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Code Behind:</strong></p>
  
  <pre><code>using System.Windows;
  using System.ComponentModel;
  using System.Windows.Media;
  
  namespace TestBackground88238
  {
      public partial class Window1 : Window, INotifyPropertyChanged
      {
  
          #region ViewModelProperty: Background
          private Brush _background;
          public Brush Background
          {
              get
              {
                  return _background;
              }
  
              set
              {
                  _background = value;
                  OnPropertyChanged("Background");
              }
          }
          #endregion
  
          #region ViewModelProperty: Message
          private string _message;
          public string Message
          {
              get
              {
                  return _message;
              }
  
              set
              {
                  _message = value;
                  OnPropertyChanged("Message");
              }
          }
          #endregion
  
          public Window1()
          {
              InitializeComponent();
              DataContext = this;
  
              Background = new SolidColorBrush(Colors.Red);
              Message = "This is the title, the background should be " + Background + ".";
  
              Message2.Background = new SolidColorBrush(Colors.Orange);
  
          }
  
          #region INotifiedProperty Block
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected void OnPropertyChanged(string propertyName)
          {
              PropertyChangedEventHandler handler = PropertyChanged;
  
              if (handler != null)
              {
                  handler(this, new PropertyChangedEventArgs(propertyName));
              }
          }
          #endregion
  
      }
  }
  </code></pre>