title: WPF Styles, BasedOn, & Storyboards
body: <p>I am trying to create a simple style that highlights the focused UI Element (Textbox,combo,etc) while it has focus, and goes away when lost focus. </p>
  
  <p>I came up with this: `</p>
  
  <pre><code>    &lt;Style TargetType="{x:Type FrameworkElement}" x:Key="OnFocus"&gt;
          &lt;Setter Property="Effect"&gt;
              &lt;Setter.Value&gt;
                  &lt;DropShadowEffect Color="Red" 
                          BlurRadius="0" 
                          ShadowDepth='0' /&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
          &lt;Style.Triggers&gt;
              &lt;EventTrigger RoutedEvent="UIElement.GotFocus"&gt;
                      &lt;BeginStoryboard  Name="highlight"&gt;
                          &lt;Storyboard&gt;
                              &lt;DoubleAnimation  
                Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.BlurRadius)" 
                             To="8" 
                             Duration="0:0:0.5" /&gt;
                          &lt;/Storyboard&gt;
                      &lt;/BeginStoryboard&gt;
  
                  &lt;/EventTrigger&gt;
              &lt;EventTrigger RoutedEvent="UIElement.LostFocus"&gt;
                  &lt;RemoveStoryboard  BeginStoryboardName="highlight"&gt;&lt;/RemoveStoryboard&gt;
              &lt;/EventTrigger&gt;
  
          &lt;/Style.Triggers&gt;
  
  
      &lt;/Style&gt;`
  </code></pre>
  
  <p>But if I try and create simple BasedOn styles, it cannot find the BeginStoryboardName="highlight", so each of the elements ends up having the whole Style.Triggers. </p>
  
  <p>Is there a better way of doing this? </p>