WPF编程,如何实现颜色的时间渐变?注意:不是位置渐变。

zcwymfyxzg 2011-12-02 11:51:13
位置渐变我已经实现。


我希望时间渐变:
我想当鼠标移动到按扭上的时候,按扭背景颜色慢慢变成红色,而不是瞬间变成红色。

如何实现?
...全文
206 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wushuai1346 2011-12-02
  • 打赏
  • 举报
回复
可以定义一个Timer,然后在其中写代码;或者使用线程的睡眠功能,查下MSDN吧
zcwymfyxzg 2011-12-02
  • 打赏
  • 举报
回复
非常好。


[Quote=引用 4 楼 assky124 的回复:]
一个简单的例子

XML code

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWind……
[/Quote]
Bullatus 2011-12-02
  • 打赏
  • 举报
回复
4楼已经很明确的给出了,用ColorAnimationUsingKeyFrames。
这个动画会将A,R,G,B这四个值从当前的值逐渐向目标值过渡

如果你一开始是无色,想逐渐变成红色的话,可以将RGB设置成红,将A设置为0,然后在动画中提升A值
linwenlei 2011-12-02
  • 打赏
  • 举报
回复
用连个时间。按钮的button1_MouseEnter 和button1_MouseLeave事件。然后加上timer控件调节RGB就能达到效果了。
assky124 2011-12-02
  • 打赏
  • 举报
回复
一个简单的例子

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="Storyboard1">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
<EasingColorKeyFrame KeyTime="0" Value="#FF131360"/>
<EasingColorKeyFrame KeyTime="0:0:2" Value="#FF13601F"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</EventTrigger>
</Window.Triggers>

<Grid x:Name="LayoutRoot">
<Rectangle x:Name="rectangle" Fill="#FFF4F4F5" Height="60" Margin="205,144,296,0" Stroke="Black" VerticalAlignment="Top"/>
</Grid>
</Window>
assky124 2011-12-02
  • 打赏
  • 举报
回复
装个Blend,直接设计动画
  • 打赏
  • 举报
回复
在timer里面写改变背景rgb颜色,鼠标移动到控件上的时候启动时间控件。

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧