c# - 悬停在 UserControl 中时的动画
问题描述
我想制作一个具有 2 个 Background 和 BGHover 属性的 UserControl。当您将光标悬停在 UserControl 上时,Background 控件将更改为 BGHover(很可能在 ColorAnimation 的帮助下),并且当 MouseLeave Background 更改回原来的那个时。
SolidColorBrush bgColor = (SolidColorBrush)Background;
this.MouseEnter += delegate (object sender, MouseEventArgs e) {
bgColor = (SolidColorBrush)Background;
DoubleAnimation anim = new DoubleAnimation(0, myBtn.Width, TimeSpan.FromMilliseconds(200));
indicatorBtn.BeginAnimation(WidthProperty, anim);
ColorAnimation animC = new ColorAnimation(BGHover, TimeSpan.FromMilliseconds(200));
myBtn.Background.BeginAnimation(SolidColorBrush.ColorProperty, animC);
};
this.MouseLeave += delegate (object sender, MouseEventArgs e) {
DoubleAnimation anim = new DoubleAnimation(myBtn.Width, 0, TimeSpan.FromMilliseconds(200));
indicatorBtn.BeginAnimation(WidthProperty, anim);
ColorAnimation animC = new ColorAnimation(BGHover, Color.FromArgb(bgColor.Color.A, bgColor.Color.R, bgColor.Color.G, bgColor.Color.B), TimeSpan.FromMilliseconds(200));
myBtn.Background.BeginAnimation(SolidColorBrush.ColorProperty, animC);
};
通过悬停,我将背景更改为 BGHover 颜色。但是使用 MouseLeave,颜色保持与 BGHover 相同。
解决方案
推荐阅读
- java - 我正在尝试创建一种方法来查找树中的父节点和祖父节点,但我不断收到 nullptr 异常
- python - Python pandas:从数据帧的每一行构造列表数据类对象
- python - 修复 OpenCV Python 流摄取
- html - 使用带有表格滚动且无页面滚动的 CSS Grid 的带有粘性标题的表格
- blockchain - 以太坊/BSC 区块链交易数据
- pandas - 一个双胞胎人物上的两个 Seaborn 情节变得扭曲
- hyperledger-fabric - 超级账本结构链码事件
- excel - 如何在 VBA 中为我的 cmd 计划任务创建参数?
- python - Pandas - 从字典创建数据框时重复行
- kotlin - Kotlin - Firestore - 带有两个集合的内部查询并将其传递给 mutableList