wpf-118169-common-concepts-data-sources-realtimesource.md
The RealTimeSource component is designed to display small amounts of rapidly changing data while keeping the user interface responsive.
Note
The RealTimeSource can effectively work with data sources with not more then several hundred data records.
The following animation demonstrates a GridControl bound to dynamic data using the RealTimeSource.
You should consider using the RealTimeSource component if records in your data source are frequently updated (e.g., 20 000 updates per second).
The use of the RealTimeSource with static data will not result in any performance improvements.
Note
The RealTimeSource is a layer between a data-aware control and the actual data.
Before you decide to use the RealTimeSource component in your application, consider the following limitations.
You can bind any data-aware control to the RealTimeSource. The GridControl is taken as an example.
To display real-time data in the GridControl, do the following.
In code, create a RealTimeSource object. Use its RealTimeSource.DataSource property to link a real-time source to your data.
Set the LookUpEditBase.ItemsSource property (via GridControl .ItemsSource ) to your RealTimeSource object.
ObservableCollection<Data> Persons;
//...
DevExpress.Data.RealTimeSource myRealTimeSource = new DevExpress.Data.RealTimeSource();
myRealTimeSource.DataSource = Persons;
myGridControl.ItemsSource = myRealTimeSource;
The following table describes additional RealTimeSource configuration scenarios.
|
Scenario
|
Approach
| | --- | --- | |
Specify which data source properties
are passed to a data-aware control.
|
Specify the required data source properties using the RealTimeSource.DisplayableProperties property.
//A semicolon-separated list of data source property names
myRealTimeSource.DisplayableProperties = "Id;Progress";
| |
Ignore modifications of individual property values.
|
Set the RealTimeSource.IgnoreItemEvents property to true.
Modifications of data source items will be ignored by the RealTimeSource.
Only modifications made to the data source list will be passed to a data-aware control.
|
This example demonstrates how to use the RealTimeSource component to display rapidly changing data within the GridControl.
Note
Data in this example is randomly generated for demonstration purposes.
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows
Imports System.Collections.ObjectModel
Imports System.Globalization
Imports System.Windows.Data
Imports System.Windows.Markup
Imports DevExpress.Data
Imports System.Windows.Threading
Imports System.ComponentModel
Namespace RealTimeSourceExample
Partial Public Class MainWindow
Inherits Window
Private Persons As ObservableCollection(Of Data)
Private Count As Integer = 50
Private Random As New Random()
Public Sub New()
InitializeComponent()
Persons = New ObservableCollection(Of Data)()
For i As Integer = 0 To Count - 1
Persons.Add(New Data With {.Id = i, .Text = "Text" & i, .Progress = GetNumber()})
Next i
grid.ItemsSource = New RealTimeSource() With {.DataSource = Persons}
Dim timer As New DispatcherTimer()
timer.Interval = TimeSpan.FromMilliseconds(1)
AddHandler timer.Tick, AddressOf Tick
timer.Start()
End Sub
Private Sub Tick(ByVal sender As Object, ByVal e As EventArgs)
Dim index As Integer = Random.Next(0, Count)
Persons(index).Id = GetNumber()
Persons(index).Text = "Text" & GetNumber()
Persons(index).Progress = GetNumber()
End Sub
Private Function GetNumber() As Integer
Return Random.Next(0, Count)
End Function
End Class
Public Class Data
Implements INotifyPropertyChanged
Private _Id As Integer
Public _Text As String
Public _Progress As Double
Public Property Id() As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
NotifyPropertyChanged("Id")
End Set
End Property
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal value As String)
_Text = value
NotifyPropertyChanged("Text")
End Set
End Property
Public Property Progress() As Double
Get
Return _Progress
End Get
Set(ByVal value As Double)
_Progress = value
NotifyPropertyChanged("Progress")
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal name As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
End Sub
End Class
End Namespace
<Window
x:Class="RealTimeSourceExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:local="clr-namespace:RealTimeSourceExample"
Name="win"
Title="MainWindow"
Height="350"
Width="525">
<Grid>
<dxg:GridControl x:Name="grid">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Id"/>
<dxg:GridColumn FieldName="Text"/>
<dxg:GridColumn FieldName="Progress">
<dxg:GridColumn.EditSettings>
<dxe:ProgressBarEditSettings/>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView Name="view" AutoWidth="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
using DevExpress.Data;
using System.Windows.Threading;
using System.ComponentModel;
namespace RealTimeSourceExample {
public partial class MainWindow: Window {
ObservableCollection<Data> Persons;
int Count = 50;
Random Random = new Random();
public MainWindow() {
InitializeComponent();
Persons = new ObservableCollection<Data>();
for (int i = 0; i < Count; i++)
Persons.Add(new Data {
Id = i,
Text = "Text" + i,
Progress = GetNumber()
});
grid.ItemsSource = new RealTimeSource() {
DataSource = Persons
};
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(1);
timer.Tick += Tick;
timer.Start();
}
private void Tick(object sender, EventArgs e) {
int index = Random.Next(0, Count);
Persons[index].Id = GetNumber();
Persons[index].Text = "Text" + GetNumber();
Persons[index].Progress = GetNumber();
}
int GetNumber() {
return Random.Next(0, Count);
}
}
public class Data: INotifyPropertyChanged {
private int _Id;
public string _Text;
public double _Progress;
public int Id {
get {
return _Id;
}
set {
_Id = value;
NotifyPropertyChanged("Id");
}
}
public string Text {
get {
return _Text;
}
set {
_Text = value;
NotifyPropertyChanged("Text");
}
}
public double Progress {
get {
return _Progress;
}
set {
_Progress = value;
NotifyPropertyChanged("Progress");
}
}
public event PropertyChangedEventHandler PropertyChanged;
void NotifyPropertyChanged(string name) {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}