1
votes

I want to be able to Fade In a Border in Code Behind (C#) when the user hovers over a Rectangle in my application.

I've seen a few examples of creating animations in Code behind but cannot get them to work for this instance.

As you can see, I have a MouseEnter event that at the moment, created a border around the object but I want this to Fade In (and out when I have a MouseLeave event)

Can you please help to understand what I need?

private void ImageRect_MouseEnter(object sender, MouseEventArgs e) { SolidColorBrush blueBrush = new SolidColorBrush(); blueBrush.Color = SystemColors.HighlightColor; ImageRect.StrokeThickness = 3; ImageRect.Stroke = blueBrush; }

Thanks very much

Shaun

1

1 Answers

2
votes

try to use this when you want to create storyboard in code behind.

Storyboard strybrd = new Storyboard();

            var mycolor = new ColorAnimation { };

            Storyboard.SetTarget(mycolor, ImageRect);
            Storyboard.SetTargetProperty(mycolor, new PropertyPath("(Rectangle.Stroke).(SolidColorBrush.Color)"));
            mycolor.To = Color.FromArgb(255, 150, 150, 151);

            strybrd.Begin();