日期:2014-05-20  浏览次数:20671 次

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


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

如何实现?

------解决方案--------------------
一个简单的例子
XML code

<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>