Doubleanimation in cell background

2 Answers 152 Views
GridView
Peter
Top achievements
Rank 1
Iron
Iron
Peter asked on 30 Jan 2022, 07:20 PM

Hello.

In radgridview i change the colors of the cells in the cellloaded event, which wotks fine, but

is there any way to use doubleanimate the backgroudn color of a cell?

 

This is how i color now:

 

Private Sub dgw_PL_CellLoaded(sender As Object, e As CellEventArgs) Handles dgw_PL.CellLoaded
        If TypeOf e.Cell Is GridViewHeaderCell Or TypeOf e.Cell Is GridViewFooterCell Then
            Exit Sub
        End If
        If e.Cell.Column.DisplayIndex < 7 Then
            e.Cell.Background = Brushes.LightSteelBlue
        End If
        Dim G As Telerik.Windows.Controls.GridView.GridViewCell = e.Cell
        If e.Cell.Column.UniqueName.ToString.ToUpper.Contains("DEM") Then
            If e.Cell.Column.DisplayIndex > 6 AndAlso (G.Content.text = "0" Or G.Value > 0) Then
                G.Background = New SolidColorBrush(Color.FromRgb(200, 255, 215))
            End If
        End If
End Sub

 

How could i make it for example blink between two colors, with doubleanimation?

 

Thanks

Peter

Stenly
Telerik team
commented on 02 Feb 2022, 05:02 PM

I will review the requirement for the double color blinking and will come back to you with more information on how to achieve the wanted result.

2 Answers, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 03 Feb 2022, 07:58 AM

Hello Peter,

To make the cells blink between colors, you could create a new Style with TargetType="GridViewCell" and create a new EventTrigger for the Loaded event. Then, inside the EventTrigger.Actions property, create a new BeginStoryBoard with a StoryBoard instance inside. After that, add two ColorAnimations and set theirs From and To properties to the desired colors. It is important to correctly utilize the BeginTime property of the animations, otherwise, the colors will overlap.

The following code snippet shows this approach's implementation:

<Style TargetType="telerik:GridViewCell">
    <Style.Triggers>
        <EventTrigger RoutedEvent="telerik:GridViewCell.Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard x:Name="beginStoryBoard">
                    <Storyboard>
                        <ColorAnimation Storyboard.TargetProperty="Background.Color"
                                        Duration="0:0:0.5"  From="#00FFFFFF" To="Red" BeginTime="0" AutoReverse="True"/>
                        <ColorAnimation Storyboard.TargetProperty="Background.Color"
                                        Duration="0:0:0.7"  From="#00FFFFFF" To="Purple" BeginTime="0:0:1" AutoReverse="True"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Style.Triggers>
</Style>

With that said, I have attached a sample project, so, could you give it a try?

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Peter
Top achievements
Rank 1
Iron
Iron
commented on 06 Feb 2022, 08:59 AM

Hello, 

Thank you, this is similar what i try to achieve, but not the whole , only a few has to be blinked , bsed on the value of the cell.

Can you please give a vb.net example instead of xaml approach? like in my example?

Here a checkbox column goes red if its checked, but i want to make it blink between the two colors... 
i tried to do it based on your xaml example, but couldnt achiveve the same.....

     

 Private Sub dgw_PL_CellLoaded(sender As Object, e As CellEventArgs) Handles dgw_PL.CellLoaded
        If TypeOf e.Cell Is GridViewHeaderCell Or TypeOf e.Cell Is GridViewFooterCell Then
            Exit Sub
        End If
   Dim G As Telerik.Windows.Controls.GridView.GridViewCell = e.Cell
        If e.Cell.Column.DisplayIndex = 6 AndAlso (G.Content.ischecked = True) Then
            ''''this is the current code, solid color:
            ''''G.Background = New SolidColorBrush(Color.FromRgb(240, 130, 0))'
            '''HERE COMES THE BLINKING CODE????

        End If
    End Sub

 

 

Peter

0
Peter
Top achievements
Rank 1
Iron
Iron
answered on 06 Feb 2022, 09:05 AM

Hello Again,

 

Leave it, i figured it out!

 

I share it if someone else needs it too. In my above code just insert:

        If e.Cell.Column.DisplayIndex = 6 AndAlso (G.Content.ischecked = True) Then


            Dim brush As SolidColorBrush = New SolidColorBrush(Colors.Red)
            G.Background = brush
            Dim animation As ColorAnimation = New ColorAnimation(Colors.Red, Colors.White, New Duration(TimeSpan.FromSeconds(1)))
            animation.AutoReverse = True
            animation.RepeatBehavior = RepeatBehavior.Forever
            brush.BeginAnimation(SolidColorBrush.ColorProperty, animation)

        End If

 

End Sub

Tags
GridView
Asked by
Peter
Top achievements
Rank 1
Iron
Iron
Answers by
Stenly
Telerik team
Peter
Top achievements
Rank 1
Iron
Iron
Share this question
or