Guest User

http://meta.stackoverflow.com/questions/173194/auto-deletion

a guest
Mar 23rd, 2013
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. I wrote a couple of simple Storyboards for highlighting an element in my UI:
  2.  
  3. <Storyboard x:Key="highlightStoryboard" Storyboard.TargetProperty="Stroke.Color">
  4. <ColorAnimation To="#ff4444" Duration="0:0:0.2" />
  5. <ColorAnimation BeginTime="0:0:0.2" RepeatBehavior="Forever" AutoReverse="True" To="#ffcccc" Duration="0:0:0.5" />
  6. </Storyboard>
  7.  
  8. <Storyboard x:Key="unlightStoryboard" Storyboard.TargetProperty="Stroke.Color">
  9. <ColorAnimation Duration="0:0:0.5" FillBehavior="Stop"/>
  10. </Storyboard>
  11.  
  12. I use Styles and Triggers to apply these when the mouse is over an appropriate element:
  13.  
  14. <Style TargetType ="{x:Type Rectangle}">
  15. <Style.Triggers>
  16. <Trigger Property="IsMouseOver" Value="True">
  17. <Trigger.EnterActions>
  18. <BeginStoryboard Storyboard="{StaticResource highlightStoryboard}"/>
  19. </Trigger.EnterActions>
  20. <Trigger.ExitActions>
  21. <BeginStoryboard Storyboard="{StaticResource unlightStoryboard}"/>
  22. </Trigger.ExitActions>
  23. </Trigger>
  24. </Style.Triggers>
  25. </Style>
  26.  
  27. These are all defined in resources.
  28.  
  29. This all works quite nicely. However, now I'd like to apply the same animation to a different element. Lets say a TextBox. However the Stroke.Color property is not appropriate. I need to apply that animation to the BorderBrush.Color property instead. For a different element again it would be Foreground.Color property...
  30.  
  31. I was hoping I could move the Storyboard.TargetProperty down into the BeginStoryboard, but no dice - I get an exception at runtime complaining that the TargetProperty has not been set.
  32.  
  33. For now I've duplicated the Storyboards for each target property, but that's horrible. My only other thought was to use an attached property which I can target in the animation, and then bind that to the actual property used per-object.
  34.  
  35. Is there a better way of doing this?
Add Comment
Please, Sign In to add comment