title: Binding a WPF Style Trigger to a custom dependency property
body: <p>I have found numerous similar threads here, but none that seem to address my specific issue.</p>
  
  <p>I need to highlight the background of a textbox under certain conditions.  I have created a Highlight property and tried using a trigger in a style to set it but it doesn't actually ever highlight the text.</p>
  
  <p>Here is my Style, simplified:</p>
  
  <pre><code>&lt;Style x:Key="TextBoxStyle" BasedOn="{StaticResource CommonStyles}"&gt;
      &lt;Style.Triggers&gt;
          &lt;Trigger Property="Elements:DataElement.Highlight" Value="True"&gt;
              &lt;Setter Property="Control.Background"
                      Value="{DynamicResource EntryBoxHighlightBackground}"/&gt;
          &lt;/Trigger&gt;
      &lt;/Style.Triggers&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>Elements is defined as:</p>
  
  <pre><code>xmlns:Elements="clr-namespace:MDTCommon.Controls.Forms.Elements"&gt;
  </code></pre>
  
  <p>Then I have the section where the style is applied:</p>
  
  <pre><code>&lt;!-- Applies above style to all TextBoxes --&gt;
  &lt;Style TargetType="TextBox" BasedOn="{StaticResource TextBoxContentHolder}" &gt;
      &lt;Setter Property="Validation.ErrorTemplate" Value="{x:Null}" /&gt;
      &lt;!-- Overrides the default Error Style --&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>In the code behind of the DataElement class is the following:</p>
  
  <pre><code>public static readonly DependencyProperty HighlightProperty = 
      DependencyProperty.Register("Highlight", typeof(bool), typeof(DataElement));
  
  public bool Highlight
  {
      get { return (bool)base.GetValue(HighlightProperty); }
      set { base.SetValue(HighlightProperty, value); }
  }
  </code></pre>
  
  <p>A DataElement ultimately derived from UserControl and it contains a reference to TextBox object as well as othe objects.</p>
  
  <p>In the CustomForm class that houses all of the DataElement objects I have the following to set the color.</p>
  
  <pre><code>Resources["EntryBoxHighlightBackground"] = Brushes.Yellow;
  </code></pre>
  
  <p>So, the first issue is that setting the Highlight property for the DataElement doesn't cause the textbox background to draw in yellow.</p>
  
  <p>The other issue is that I realize that I am applying this style to all textboxes and I could have textboxes in other areas that are not actually contained within a DataElement, which may cause a binding issue.</p>