ColorAnimation StoryBoard : Color « Animations « Silverlight






ColorAnimation StoryBoard

ColorAnimation StoryBoard
    

<UserControl x:Class='SilverlightApplication3.MainPage'
    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
    xmlns:d='http://schemas.microsoft.com/expression/blend/2008' 
    xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
    mc:Ignorable='d' 
    d:DesignWidth='640' d:DesignHeight='480'>
    <UserControl.Resources>
        <Storyboard x:Name="TurnBlue">
            <ColorAnimation Storyboard.TargetName="RedEllipse" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Duration="00:00:00.50" To="#FF0D0874"/>
        </Storyboard>
        <Storyboard x:Name="TurnRed">
            <ColorAnimation Storyboard.TargetName="RedEllipse" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Duration="00:00:00.50" To="#FFFF0000"/>
        </Storyboard>
    </UserControl.Resources>

    <Canvas x:Name="LayoutRoot" Background="White" >
        <Ellipse Height="218" Width="218" Canvas.Left="294" Canvas.Top="195" Fill="#FFFF0000" Cursor="Hand" x:Name="RedEllipse"/>
    </Canvas>
</UserControl>


//File: Page.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication3
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            RedEllipse.MouseEnter += new MouseEventHandler(RedEllipse_MouseEnter);
            RedEllipse.MouseLeave += new MouseEventHandler(RedEllipse_MouseLeave);
        }
        void RedEllipse_MouseLeave(object sender, MouseEventArgs e)
        {
            TurnRed.Begin();
        }

        void RedEllipse_MouseEnter(object sender, MouseEventArgs e)
        {
            TurnBlue.Begin();
        }
    }
}

   
    
    
    
  








Related examples in the same category

1.Color Animation EffectsColor Animation Effects
2.Animate the Color of a Brush with Indirect Property Targeting
3.Animate the background color
4.Color From To By AnimationColor From To By Animation
5.Use ColorAnimationUsingKeyFrames to animate GradientStopUse ColorAnimationUsingKeyFrames to animate GradientStop
6.Use code to control color animationUse code to control color animation
7.Repetition countRepetition count
8.Animate RadialGradient