Blinking settings such as duration.

Namespace: Dapfor.Wpf.Controls
Assembly: Dapfor.Wpf (in Dapfor.Wpf.dll) Version: 4.1.0.26317 (4.1.0.26317)

Syntax

C#
[TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public class GridControlBlinkingSettings : INotifyPropertyChanged
Visual Basic
<TypeConverterAttribute(GetType(ExpandableObjectConverter))>
Public Class GridControlBlinkingSettings
	Implements INotifyPropertyChanged
Visual C++
[TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public ref class GridControlBlinkingSettings : INotifyPropertyChanged
F#
[<TypeConverterAttribute(typeof(ExpandableObjectConverter))>]
type GridControlBlinkingSettings =  
    class
        interface INotifyPropertyChanged
    end

Remarks

Blinking of rapidly changing data in cells is an important element of modern applications. Implementation usually requires creation of timers, tracking blinking end time to restore the original background and creation of a DataTemplate with necessary triggers. All these tasks require a lot of work and high programming skills. Besides, implementation based on usage of DataTemplate cannot have high performance will consume a lot of CPU and memory resources.

GridControl provides a simple and convenient interface for blinking a cell for the defined period of time with selected color. To use it, one only has to transmit the required parameters to Cell.Blink(TimeSpan, Brush). The grid automatically creates timers, tracks their expiration and manages the blinking process. An example of blinking a grid cell in red for 1 second is shown below.

 Copy imageCopy
Cell.Blink(TimeSpan.FromMilliseconds(1000), Brushes.Red);

When INotifyPropertyChanged is implemented via data objects, GridControl subscribes to each such object. After receiving notification and performing required synchronization the grid performs such activities as automated sorting, filtering, grouping, cell content updating. Besides the above activities, the grid also performs cell blinking. It uses default time and color values. However, they can be easily redefined with XAML code:

 Copy imageCopy
<!-- Declare resources -->
<Window.Resources>
    <RadialGradientBrush x:Key="BlinkBrush">
        <GradientStop Color="#00FFA500" Offset="1"/>
        <GradientStop Color="#64FFA500" Offset=".6"/>
        <GradientStop Color="#9BFFA500" Offset="0"/>
    </RadialGradientBrush>
</Window.Resources>

<df:GridControl AppearanceCellBlinkBackground="{StaticResource BlinkBrush}">
    <!-- Headers and other parameters -->
</df:GridControl>

It is also possible to change blinking parameters in code:

 Copy imageCopy
grid.SettingsBlinking.Enabled = true;
grid.SettingsBlinking.Duration = TimeSpan.FromMilliseconds(5000);
grid.AppearanceCellBlinkBackground = Brushes.Red;

When the grid receives a notification from INotifyPropertyChanged, it checks GridControl.SettingsBlinking.Enabled flag. If this flag is set, the grid calls Cell.Blink(TimeSpan, Brush) for the corresponding cell.

In actual applications cells should be highlighted with different colors. For example, blinking may depend on product price change. The best way to achieve this is subscription to GridControl.RowUpdated event that is always called in the main thread where the programmer receives access to the modified data object and to information about changes. An example of blinking a price cell in green or red depending on value change is provided below.

 Copy imageCopy
//Blink 'Price' cell green when the price goes up and red when reduced. 
grid.RowUpdated += (sender, e) =>
{
   if (e.DataField.Id == "Price")
   {
       var share = (Share) e.Row.DataObject;
       Brush color = share.Price > share.PrevPrice ? Brushes.Green : Brushes.Red;

       //Blink the cell with the selected color 
       e.Row["Price"].Blink(TimeSpan.FromMilliseconds(1000), color);

       //Highlights some other cell with other color when Share.Price is changed 
       e.Row["OtherField"].Blink(TimeSpan.FromMilliseconds(1000), Brushes.Orange);
   }
};

Implementation of cell blinking in WPF requires fairly complex solutions that enable most efficient use of processor and memory resources. Let's give an example of problems that a programmer may face when implementing efficient cell blinking:

  • Storing time intervals of modified data
  • Storing color information
  • Managing timers to restore initial cell color
  • Optimization by blinking only cells in visible area of the grid.
  • Processing information of vertical and horizontal scrolling when off-screen rows and columns become visible.
  • Processing information of filtering, grouping, sorting, parent row expanding and collapsing when rows may move to visible area of the grid.
  • Managing grid closing timers to avoid application crash.
  • Synchronizing threads, if data changes occur in any thread other than the main thread.

The above problems make it complicated to implement cell blinking and require high programming skills. Incorrect implementation results in excessive computing resource consumption. Dapfor's framework handles all complexities of cell blinking process. This results in high grid performance enabling blinking of over 20 000 cells per second. If data is updated in non-GUI thread, the grid automatically performs synchronization providing blinking speed of over 10 000 updates per second.

Inheritance Hierarchy

System..::..Object
  Dapfor.Wpf.Controls..::..GridControlBlinkingSettings

See Also