Silverlight - 在代码隐藏中动画矩形描边

发布于 2024-10-31 18:05:59 字数 505 浏览 7 评论 0原文

当用户将鼠标悬停在我的应用程序中的矩形上时,我希望能够在代码隐藏 (C#) 中淡入边框。

我已经看到了一些在代码隐藏中创建动画的示例,但无法让它们适用于此实例。

正如您所看到的,我有一个 MouseEnter 事件,目前在对象周围创建了一个边框,但我希望它淡入(当我有 MouseLeave 事件时淡出)

您能帮助理解我需要什么吗?

私有无效ImageRect_MouseEnter(对象发送者,MouseEventArgs e) { SolidColorBrush blueBrush = new SolidColorBrush(); blueBrush.Color = SystemColors.HighlightColor; ImageRect.StrokeThickness = 3; ImageRect.Stroke = blueBrush; 肖恩

非常

感谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜无邪 2024-11-07 18:05:59

当您想在代码隐藏中创建故事板时,请尝试使用此选项。

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();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文