Results 1 to 3 of 3

Thread: [RESOLVED] Animating a gradient brush

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Resolved [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?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    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.

  3. #3

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width