title: How can I add the validation style to all my custom controls and still be DRY?
body: <p>I'm currently building some custom controls in Silverlight. I want these controls to respond to validation errors. What I'm trying to do is to get that red border around my control, just like the default Silverlight controls.</p>
  
  <p>What I understand is that I need to add this to my template:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;VisualStateManager.VisualStateGroups&gt;
    &lt;VisualStateGroup x:Name="ValidationStates"&gt;
      &lt;VisualState x:Name="Valid"/&gt;
      &lt;VisualState x:Name="InvalidUnfocused"&gt;
        &lt;Storyboard&gt;
          &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility"&gt;
            &lt;DiscreteObjectKeyFrame KeyTime="0"&gt;
              &lt;DiscreteObjectKeyFrame.Value&gt;
                &lt;Visibility&gt;Visible&lt;/Visibility&gt;
              &lt;/DiscreteObjectKeyFrame.Value&gt;
            &lt;/DiscreteObjectKeyFrame&gt;
          &lt;/ObjectAnimationUsingKeyFrames&gt;
        &lt;/Storyboard&gt;
      &lt;/VisualState&gt;
      &lt;VisualState x:Name="InvalidFocused"&gt;
        &lt;Storyboard&gt;
          &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility"&gt;
            &lt;DiscreteObjectKeyFrame KeyTime="0"&gt;
              &lt;DiscreteObjectKeyFrame.Value&gt;
                &lt;Visibility&gt;Visible&lt;/Visibility&gt;
              &lt;/DiscreteObjectKeyFrame.Value&gt;
            &lt;/DiscreteObjectKeyFrame&gt;
          &lt;/ObjectAnimationUsingKeyFrames&gt;
          &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsOpen"&gt;
            &lt;DiscreteObjectKeyFrame KeyTime="0"&gt;
              &lt;DiscreteObjectKeyFrame.Value&gt;
                &lt;sys:Boolean&gt;True&lt;/sys:Boolean&gt;
              &lt;/DiscreteObjectKeyFrame.Value&gt;
            &lt;/DiscreteObjectKeyFrame&gt;
          &lt;/ObjectAnimationUsingKeyFrames&gt;
        &lt;/Storyboard&gt;
      &lt;/VisualState&gt;
    &lt;/VisualStateGroup&gt;
  &lt;/VisualStateManager.VisualStateGroups&gt;
  </code></pre>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Border x:Name="ValidationErrorElement" BorderThickness="1" CornerRadius="1" BorderBrush="#FFDB000C" Visibility="Collapsed"&gt;
    &lt;ToolTipService.ToolTip&gt;
      &lt;ToolTip x:Name="validationTooltip" Template="{StaticResource ValidationToolTipTemplate}" Placement="Right"
                PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"&gt;
        &lt;ToolTip.Triggers&gt;
          &lt;EventTrigger RoutedEvent="Canvas.Loaded"&gt;
            &lt;EventTrigger.Actions&gt;
              &lt;BeginStoryboard&gt;
                &lt;Storyboard&gt;
                  &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsHitTestVisible"&gt;
                    &lt;DiscreteObjectKeyFrame KeyTime="0"&gt;
                      &lt;DiscreteObjectKeyFrame.Value&gt;
                        &lt;sys:Boolean&gt;true&lt;/sys:Boolean&gt;
                      &lt;/DiscreteObjectKeyFrame.Value&gt;
                    &lt;/DiscreteObjectKeyFrame&gt;
                  &lt;/ObjectAnimationUsingKeyFrames&gt;
                &lt;/Storyboard&gt;
              &lt;/BeginStoryboard&gt;
            &lt;/EventTrigger.Actions&gt;
          &lt;/EventTrigger&gt;
        &lt;/ToolTip.Triggers&gt;
      &lt;/ToolTip&gt;
    &lt;/ToolTipService.ToolTip&gt;
    &lt;Grid Width="12" Height="12" HorizontalAlignment="Right" Margin="1,-4,-4,0" VerticalAlignment="Top" Background="Transparent"&gt;
      &lt;Path Margin="1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="#FFDC000C"/&gt;
      &lt;Path Margin="1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8" Fill="#ffffff"/&gt;
    &lt;/Grid&gt;
  &lt;/Border&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ControlTemplate x:Key="ValidationToolTipTemplate"&gt;
    &lt;Grid x:Name="Root" Margin="5,0" RenderTransformOrigin="0,0" Opacity="0"&gt;
      &lt;Grid.RenderTransform&gt;
        &lt;TranslateTransform x:Name="xform" X="-25"/&gt;
      &lt;/Grid.RenderTransform&gt;
      &lt;VisualStateManager.VisualStateGroups&gt;
        &lt;VisualStateGroup Name="OpenStates"&gt;
          &lt;VisualStateGroup.Transitions&gt;
            &lt;VisualTransition GeneratedDuration="0"/&gt;
            &lt;VisualTransition To="Open" GeneratedDuration="0:0:0.2"&gt;
              &lt;Storyboard&gt;
                &lt;DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="X" To="0" Duration="0:0:0.2"&gt;
                  &lt;DoubleAnimation.EasingFunction&gt;
                    &lt;BackEase Amplitude=".3" EasingMode="EaseOut"/&gt;
                  &lt;/DoubleAnimation.EasingFunction&gt;
                &lt;/DoubleAnimation&gt;
                &lt;DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2"/&gt;
              &lt;/Storyboard&gt;
            &lt;/VisualTransition&gt;
          &lt;/VisualStateGroup.Transitions&gt;
          &lt;VisualState x:Name="Closed"&gt;
            &lt;Storyboard&gt;
              &lt;DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0" Duration="0"/&gt;
            &lt;/Storyboard&gt;
          &lt;/VisualState&gt;
          &lt;VisualState x:Name="Open"&gt;
            &lt;Storyboard&gt;
              &lt;DoubleAnimation Storyboard.TargetName="xform" Storyboard.TargetProperty="X" To="0" Duration="0"/&gt;
              &lt;DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/&gt;
            &lt;/Storyboard&gt;
          &lt;/VisualState&gt;
        &lt;/VisualStateGroup&gt;
      &lt;/VisualStateManager.VisualStateGroups&gt;
  
      &lt;Border Margin="4,4,-4,-4" Background="#052A2E31" CornerRadius="5"/&gt;
      &lt;Border Margin="3,3,-3,-3" Background="#152A2E31" CornerRadius="4"/&gt;
      &lt;Border Margin="2,2,-2,-2" Background="#252A2E31" CornerRadius="3"/&gt;
      &lt;Border Margin="1,1,-1,-1" Background="#352A2E31" CornerRadius="2"/&gt;
  
      &lt;Border Background="#FFDC000C" CornerRadius="2"/&gt;
      &lt;Border CornerRadius="2"&gt;
        &lt;TextBlock
            UseLayoutRounding="false"
            Foreground="White" Margin="8,4,8,4" MaxWidth="250" TextWrapping="Wrap" Text="{Binding (Validation.Errors)[0].ErrorContent}"/&gt;
      &lt;/Border&gt;
    &lt;/Grid&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>And I need to add this for every control that I create (with the exception of the ValidationToolTipTemplate-ControlTemplate).</p>
  
  <ol>
  <li>How can I add the validation style to all my controls and still be DRY?</li>
  <li>If that is not possible, does this mean that when the style of the validation template changes, I have to copy and paste the templates of all the controls in the known universe in a file called 'generic.xaml' and change it accordingly?</li>
  </ol>
  
  <p>I've worked with Microsoft APIs long enough to know that (2) is probably the way to go, but I want to make sure first.</p>