title: WPF style/control template reuse
body: <p>I'm new to WPF, and I would like to know how to reuse some annoying xaml I have to avoid duplicating.</p>
  
  <pre><code>&lt;Button Cursor="Hand" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="MyButton" Style="{StaticResource ButtonTemplate}" Width="286" Content="hi!" Focusable="False" IsTabStop="False"/&gt;
  &lt;Button Cursor="Hand" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="MyButton2" Style="{StaticResource ButtonTemplate}" Width="286" Content="hi 2!" Focusable="False" IsTabStop="False"/&gt;
  </code></pre>
  
  <p>I'd really like to use something like this template:</p>
  
  <pre><code>&lt;Style TargetType="{x:Type Button}" x:Key="ButtonTemplate"&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type Button}"&gt;
                          &lt;Grid x:Name="btGrid"&gt;
                              &lt;Path Cursor="Hand" HorizontalAlignment="Left" Stretch="Fill" Stroke="{x:Null}" Opacity="0" x:Name="path"/&gt;
                              &lt;ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True" Visibility="Hidden" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top"/&gt;
                          &lt;/Grid&gt;
                          &lt;ControlTemplate.Triggers&gt;
                              &lt;EventTrigger RoutedEvent="Button.PreviewMouseLeftButtonDown"&gt;
                                  &lt;EventTrigger.Actions&gt;
                                      &lt;BeginStoryboard&gt;
                                          &lt;Storyboard SlipBehavior="Slip" BeginTime="00:00:00"&gt;
                                              &lt;MediaTimeline Source="{Binding StringFormat={}, Path=Name}" Storyboard.TargetName="{Binding StringFormat={}_wma, Path=Name}"/&gt;
                                                      &lt;ObjectAnimationUsingKeyFrames    Storyboard.TargetName="{Binding StringFormat=key{}, Path=Name}" 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;/BeginStoryboard&gt;
                                  &lt;/EventTrigger.Actions&gt;
                              &lt;/EventTrigger&gt;
                              &lt;EventTrigger RoutedEvent="Button.PreviewMouseLeftButtonUp"&gt;
                                  &lt;EventTrigger.Actions&gt;
                                      &lt;BeginStoryboard&gt;
                                          &lt;Storyboard&gt;
                                              &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName="{Binding StringFormat=key{}, Path=Name}" Storyboard.TargetProperty="Visibility"&gt;
              &lt;DiscreteObjectKeyFrame KeyTime="0"&gt;
                  &lt;DiscreteObjectKeyFrame.Value&gt;
                      &lt;Visibility&gt;
                          Hidden
                      &lt;/Visibility&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;Trigger Property="IsFocused" Value="True"/&gt;
                              &lt;Trigger Property="IsDefaulted" Value="True"/&gt;
                              &lt;Trigger Property="IsMouseOver" Value="True"/&gt;
                              &lt;Trigger Property="IsPressed" Value="True"/&gt;
                              &lt;Trigger Property="IsEnabled" Value="False"/&gt;
                          &lt;/ControlTemplate.Triggers&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  </code></pre>
  
  <p>And I'd like the {Binding StringFormat={}, Path=Name} to point button's name, e.g. "MyButton", "MyButton2", etc.</p>
  
  <p>When I run this code I get the error "Cannot freeze this Storyboard timeline tree for use across threads." :/ I understand this is because I use binding in a storyboard, correct? I don't know what to do to make this work.</p>
  
  <p>Also, I'd like to make the ToggleVisibility of the image a template as well, that accepts once "Visible" and once "Hidden" values.
  Thanks in advance!</p>