title: WPF UserControls; triggers and changing other controls
body: <p>I've created a WPF UserControl which contains a Button and a ComboBox. I'd like to change the style of both, depending on the position of the mouse, so the UIElement with the mouse over is coloured Black and the other is coloured Red. If neither are styled then the default styling will apply.</p>
  
  <p>Don't worry, this nightmarish colour scheme is just to illustrate the concept!</p>
  
  <p>Thanks in advance for your help.</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>&lt;UserControl x:Class="WpfUserControlSample.ToolbarButtonCombo"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               xmlns:local="clr-namespace:WpfUserControlSample"
               x:Name="Control"
               mc:Ignorable="d" 
               d:DesignHeight="30"&gt;    
      &lt;UserControl.Resources&gt;
          &lt;Style TargetType="{x:Type local:ToolbarButtonCombo}"&gt;
              &lt;Style.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding IsButtonMouseOver}" Value="True"&gt;
                      &lt;Setter Property="ButtonStyle" Value="Black"/&gt;
                      &lt;Setter Property="ComboStyle" Value="Red"/&gt;                    
                  &lt;/DataTrigger&gt;
                  &lt;!--
                  &lt;DataTrigger Binding="{Binding IsComboMouseOver}" Value="True"&gt;
                      &lt;Setter Property="ButtonStyle" Value="Red"/&gt;
                      &lt;Setter Property="ComboStyle" Value="Black"/&gt;
                  &lt;/DataTrigger&gt;
                  --&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/UserControl.Resources&gt;
      &lt;StackPanel Orientation="Horizontal" Height="30"&gt;
          &lt;Button Name="btn" Background="{Binding ButtonStyle,ElementName=Control,Mode=OneWay}"&gt;
              Test
          &lt;/Button&gt;
          &lt;ComboBox Name="cmb" Background="{Binding ComboStyle,ElementName=Control,Mode=OneWay}"&gt;&lt;/ComboBox&gt;
      &lt;/StackPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p><strong>Codebehind</strong>:</p>
  
  <pre><code>namespace WpfUserControlSample
  {
      public partial class ToolbarButtonCombo : UserControl, INotifyPropertyChanged
      {
          public event PropertyChangedEventHandler PropertyChanged;
          protected void OnPropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  
          }  
          public ToolbarButtonCombo()
          {
              InitializeComponent();
              btn.MouseEnter += new MouseEventHandler(btn_MouseChanged);
              btn.MouseLeave += new MouseEventHandler(btn_MouseChanged);
          }
          void btn_MouseChanged(object sender, MouseEventArgs e)
          {
              OnPropertyChanged("IsButtonMouseOver");
          }
  
  
          public bool IsButtonMouseOver
          {
              get { return btn.IsMouseOver; }
  
          }
          public static readonly DependencyProperty IsButtonMouseOverProperty =
              DependencyProperty.Register("IsButtonMouseOver", typeof(string), typeof(ToolbarButtonCombo), new PropertyMetadata("false"));
  
          public string ButtonStyle { get; set; }
          public static readonly DependencyProperty ButtonStyleProperty =
              DependencyProperty.Register("ButtonStyle", typeof(string), typeof(ToolbarButtonCombo));
  
          public string ComboStyle { get; set; }
          public static readonly DependencyProperty ComboStyleProperty =
              DependencyProperty.Register("ComboStyle", typeof(string), typeof(ToolbarButtonCombo));    
      }
  }
  </code></pre>