title: Change WPF StackPanel background color when an element in the panel has focus
body: <p>If I have a set of controls within a StackPanel, is there a generic way to change the background of the stackpanel when any control within the StackPanel gains focus? (and obviously switch the background back when no control in the StackPanel has focus).  The following code works for me, but it would be nice to have a generic way to accomplish this task versus having to list each control in every StackPanel in my page.</p>
  
  <p>Thanks!</p>
  
  <pre><code>&lt;StackPanel Margin="5"&gt;
      &lt;StackPanel.Style&gt;
      &lt;Style TargetType="{x:Type StackPanel}"&gt;
          &lt;Style.Triggers&gt;
              &lt;DataTrigger Binding="{Binding IsFocused, ElementName=chkOccupiedByMortgagor}" Value="true"&gt;
                  &lt;Setter Property="Background" Value="Gray" /&gt;
                  &lt;Setter Property="Opacity" Value=".5" /&gt;
              &lt;/DataTrigger&gt;
              &lt;DataTrigger Binding="{Binding IsFocused, ElementName=chkOccupiedByNewOwner}" Value="true"&gt;
                  &lt;Setter Property="Background" Value="Gray" /&gt;
                  &lt;Setter Property="Opacity" Value=".5" /&gt;
              &lt;/DataTrigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  &lt;/StackPanel.Style&gt;
  &lt;CheckBox Margin="2" x:Name="chkOccupiedByMortgagor"&gt;Mortgagor&lt;/CheckBox&gt;
  &lt;CheckBox Margin="2" x:Name="chkOccupiedByNewOwner"&gt;New Owner&lt;/CheckBox&gt;
  &lt;CheckBox Margin="2" x:Name="chkOccupiedByTenant"&gt;Tenant&lt;/CheckBox&gt;
  &lt;CheckBox Margin="2" x:Name="chkOccupiedByUnknownOccupant"&gt;Unknown Occupant&lt;/CheckBox&gt;
  &lt;/StackPanel&gt; 
  </code></pre>