Ticket Q451047
Visible to All Users

flash a cell when the displayed text is equal to MyValue

created 12 years ago

hello
I want to flash a cell when the display text in this cell is equal to "MyValue".
I have created a style and use it for a grid column : CellStyle="{StaticResource flashStyleAnimation}
<Style x:Key="flashStyleAnimation"
            BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=CellStyle}}"
            TargetType="dxg:CellContentPresenter">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=DataContext.getCeil}" Value="MyValue">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard >
                                <ColorAnimation Storyboard.TargetProperty="Background.Color"
                                                      Duration="0:0:0.2" From="White" To="Yellow" RepeatBehavior="Forever" AutoReverse="True"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
The background color of my cells does not change.
For the DataTrigger Binding I have tried <DataTrigger Binding="{Binding Path=DisplayText}" Value="MyValue"> but no success.
Have you an idea?
thank you

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hello Madeleine,
Thank you for your question and the provided code snippet.
To achieve this goal, I suggest you create a custom attached property in the following manner:

C#
class CellBackgroundChanger { public static readonly DependencyProperty IsCellValueChangedProperty = DependencyProperty.RegisterAttached("IsCellValueChanged", typeof(bool), typeof(CellBackgroundChanger), new FrameworkPropertyMetadata(false)); public static bool GetIsCellValueChanged(DependencyObject d) { return (bool)d.GetValue(IsCellValueChangedProperty); } public static void SetIsCellValueChanged(DependencyObject d, bool value) { d.SetValue(IsCellValueChangedProperty, value); } }

Then, you can handle the GridViewBase.CellValueChanged event and set a value to the attached property if the current cell value suits your needs. You can do it as shown below:

C#
private void tableView1_CellValueChanged(object sender, DevExpress.Xpf.Grid.CellValueChangedEventArgs e) { DependencyObject originalCell = gridControl1.View.GetCellElementByRowHandleAndColumn(e.RowHandle, e.Column); if(e.Value.ToString() == "MyValue") CellBackgroundChanger.SetIsCellValueChanged(originalCell, true); else CellBackgroundChanger.SetIsCellValueChanged(originalCell, false); }

In conclusion, your cell style could be defined as follows:

XAML
<Style x:Key="flashStyleAnimation" BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=CellStyle}}" TargetType="dxg:CellContentPresenter"> <Style.Triggers> <Trigger Property="local:CellBackgroundChanger.IsCellValueChanged" Value="True"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" Duration="0:0:0.2" From="White" To="Yellow" RepeatBehavior="Forever" AutoReverse="True"/> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> </Trigger> </Style.Triggers> </Style>

The following Code Central examples also demonstrate how to accomplish this task. Take a moment to review them:
1.A general approach to highlighting specific grid cells
2.How to change background color for modified cells
Please let me know if you need further assistance.
Thanks

    Show previous comments (3)
    Dmitry Tokmachev (DevExpress) 12 years ago

      Hello,
      Thank you for your question.
      In fact, this issue is not directly related to our components. It is a general WPF question, so I cannot provide you with a comprehensive solution. But I found a few articles that may be helpful to you:
      1.Multiple Storyboards or Animations that share the same timeline?
      2.We synchronize animations with WPF
      I hope this information will be useful for you.
      Thanks

        hello Dmitry,
        I have another question, when I sort my column where several cells are animated, each animation seems to be linked to a row, and the animated cells does not respect anymore my condition (flash if text cell is equal to my value).
        I tried to do an updateLayout on the column but without success.
        Do you understand my request and have you an idea?

        Alex Chuev (DevExpress) 12 years ago

          Hello Madeleine,
          Our GridControl uses a virtualization mechanism to increase performance. Row and cell elements are not recreated and can be used for various data objects depending on their current visibility. Animation in your style is attached to the cell element background, so it will not stop when the element is reused. Please refer to the KA18635: How to avoid problems with the DXGrid virtualization mechanism KB article to learn more about grid virtualization.
          Let me know if you need additional assistance.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.