|
-
Feb 20th, 2009, 02:40 PM
#1
[RESOLVED] Animating a gradient brush
Hi guys,
In my WPF app, I have some borders that have a LinearGradientBrush applied to their backgrounds and when the mouse hovers over these border controls I want the background to fade to a different LinearGradientBrush.
The way I am doing this at the moment is to create an identically sized/shaped border control on top of the existing one but set its Opacity to 0, then when the mouse goes over it I just use a DoubleAnimation to increase the opacity. This works fine and gives the exact effect I am after, but I just thought there must be a better way of doing it.
I looked at using the ColorAnimation class but I can only get this to fade to a solid colour.
Anyone got any suggestions?
-
Feb 25th, 2009, 07:44 AM
#2
Frenzied Member
Re: Animating a gradient brush
Yes, use the colors explicitly defined in the brush, ex:
Code:
<LinearGradientBrush>
<GradientStop Offset="0" Color="White" x:Name="gs0" />
<GradientStop Offset="1" Color="Black" x:Name="gs1" />
</LinearGradientBrush>
...
<ColorAnimation Storyboard.TargetName="gs0" Storyboard.TargetProperty="Color" To="Black" />
<ColorAnimation Storyboard.TargetName="gs1" Storyboard.TargetProperty="Color" To="White" />
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Feb 25th, 2009, 07:48 AM
#3
Re: Animating a gradient brush
Ahh yeah of course, I was forgetting that you could assign a name to the gradientstop elements Thanks, works like a charm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|