Quantcast
Viewing latest article 6
Browse Latest Browse All 7

Blinking Button Animation

Sounds like you need a DataTrigger:

<Window x:Class="WpfApplication64.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"><StackPanel><CheckBox IsChecked="{Binding DataChanged}" Content="DataChanged"/><Button x:Name="button" Content="Save" IsEnabled="{Binding Path=DataChanged}" Background="#FFE2E2E2"><Button.Style><Style TargetType="Button"><Style.Triggers><DataTrigger Binding="{Binding DataChanged}" Value="true"><DataTrigger.EnterActions><BeginStoryboard x:Name="sb1"><BeginStoryboard.Storyboard><Storyboard AutoReverse="True" RepeatBehavior="Forever"><ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" ><EasingColorKeyFrame KeyTime="0" Value="Red"/><EasingColorKeyFrame KeyTime="0:0:1" Value="#FF0004FF"><EasingColorKeyFrame.EasingFunction><QuinticEase EasingMode="EaseInOut"/></EasingColorKeyFrame.EasingFunction></EasingColorKeyFrame></ColorAnimationUsingKeyFrames></Storyboard></BeginStoryboard.Storyboard></BeginStoryboard></DataTrigger.EnterActions><DataTrigger.ExitActions><StopStoryboard BeginStoryboardName="sb1"/></DataTrigger.ExitActions></DataTrigger></Style.Triggers></Style></Button.Style></Button></StackPanel></Window>
using System.ComponentModel;
using System.Windows;

namespace WpfApplication64
{
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        bool _DataChanged;
        public bool DataChanged
        {
            get
            {
                return _DataChanged;
            }
            set
            {
                if (_DataChanged != value)
                {
                    _DataChanged = value;
                    RaisePropertyChanged("DataChanged");
                }
            }
        }

        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
        }

        void RaisePropertyChanged(string prop)
        {
            if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(prop)); }
        }
        public event PropertyChangedEventHandler PropertyChanged;

    }
}
 

I should say, this is changing Button Background, which is what I think you suggested. However the standard button contains ButtonChrome, which handles it's own mouseOver, click background colours, as you will notice when you try. Therefore, either you should animate the Content property, or you should restyle the button, so you have full control of the Background, as I explain here:

http://code.msdn.microsoft.com/Changing-a-WPF-Button-212386c6

I hope that answers your question, gives you enough to search further with, or at least helps :)

Regards,
Pete


#PEJL



Viewing latest article 6
Browse Latest Browse All 7

Trending Articles