This is a migrated thread and some comments may be shown as answers.

Row color animation

2 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 26 Jul 2011, 12:00 AM
I'm trying to figure out how to have a row change color and then fade back to its original color after some predetermined amount of time (like 1 second). I found this example online but can't make it fit for my situation.

http://www.telerik.com/support/kb/winforms/buttons/create-button-with-animated-border.aspx

Any input in the matter would be appreciated.

Why I'm trying to do this (in case you're interested):
I have a piece of hardware that is scanning items that are represented on the screen in the grid. As the scanner picks up an item, I'd like it to "flash" to show the user that the scanner sees it.

Thanks,
Jason

2 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 29 Jul 2011, 08:25 AM
Hello Jason,

This is possible by using the CellFormatting event and the AnimatedPropertySetting class. Please consider the following sample:
public class CustomAnimatedPropertySetting : AnimatedPropertySetting
{
    GridRowElement row;
 
    public CustomAnimatedPropertySetting(GridRowElement row)
        : base(
                LightVisualElement.BackColorProperty,
                Color.Red, // start value    
                Color.White, // end value    
                40, // number of animation frames    
                10 // time in ms between 2 frames                
        )
    {
        this.row = row;
        this.AnimationFinished += new AnimationFinishedEventHandler(CustomAnimatedPropertySetting_AnimationFinished);
        this.AnimatorStyle = AnimatorStyles.AnimateAlways;
        this.ApplyEasingType = RadEasingType.Linear;
        this.UnapplyEasingType = RadEasingType.Linear;
    }
 
    public void Stop()
    {
        GridRowElement o = this.row;
        this.row = null;
        this.Stop(o);
    }
 
    void CustomAnimatedPropertySetting_AnimationFinished(object sender, AnimationStatusEventArgs e)
    {
        if (row != null && row.Parent != null)
        {
            this.ApplyValue(row);
        }
        else
        {
            row = null;
            this.AnimationFinished -= new AnimationFinishedEventHandler(CustomAnimatedPropertySetting_AnimationFinished);
        }
    }
}
 
void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
    object value = e.RowElement.RowInfo.Cells["Check"].Value;
 
    if (value != null && (bool)value)
    {
        if (e.RowElement.Tag == null)
        {
            e.RowElement.DrawFill = true;
            e.RowElement.GradientStyle = GradientStyles.Solid;
            CustomAnimatedPropertySetting setting = new CustomAnimatedPropertySetting(e.RowElement);
            setting.ApplyValue(e.RowElement);
            e.RowElement.Tag = setting;
        }
    }
    else
    {
        CustomAnimatedPropertySetting setting = e.RowElement.Tag as CustomAnimatedPropertySetting;
        if (setting != null)
        {
            e.RowElement.Tag = null;
            setting.Stop();
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Animation | ValueResetFlags.Local);
        }
    }         
}

If you have any questions, do not hesitate to contact me.

Best wishes,
Jack
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Jason
Top achievements
Rank 1
answered on 29 Jul 2011, 11:47 PM
Thanks so much for the response, it's working now! The only thing I changed was the rowformatting event to to a cellformatting one. Thanks again.
private void m_rgvInventoryItems_CellFormatting( object sender, CellFormattingEventArgs e )
{
    if( e.CellElement.ColumnInfo.HeaderText == "Check" )
    {
        object value = e.CellElement.RowInfo.Cells[ "Check" ].Value;
 
        if( value != null && (bool)value )
        {
            if( e.CellElement.RowElement.Tag == null )
            {
                e.CellElement.RowElement.DrawFill = true;
                e.CellElement.RowElement.GradientStyle = GradientStyles.Solid;
                CustomAnimatedPropertySetting setting = new CustomAnimatedPropertySetting( e.CellElement.RowElement );
                setting.ApplyValue( e.CellElement.RowElement );
                e.CellElement.RowElement.Tag = setting;
            }
        }
        else
        {
            CustomAnimatedPropertySetting setting = e.CellElement.RowElement.Tag as CustomAnimatedPropertySetting;
            if( setting != null )
            {
                e.CellElement.RowElement.Tag = null;
                setting.Stop();
                e.CellElement.RowElement.ResetValue( LightVisualElement.DrawFillProperty, ValueResetFlags.Local );
                e.CellElement.RowElement.ResetValue( LightVisualElement.GradientStyleProperty, ValueResetFlags.Local );
                e.CellElement.RowElement.ResetValue( LightVisualElement.BackColorProperty, ValueResetFlags.Animation | ValueResetFlags.Local );
            }
        }
    }
Tags
GridView
Asked by
Jason
Top achievements
Rank 1
Answers by
Jack
Telerik team
Jason
Top achievements
Rank 1
Share this question
or