翻譯|使用教程|編輯:龔雪|2022-02-14 10:14:47.417|閱讀 294 次
概述:本文主要介紹DevExpress WPF數(shù)據(jù)源中的實(shí)時源類型,歡迎下載最新版體驗(yàn)!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
RealTimeSource 組件旨在顯示少量快速變化的數(shù)據(jù),同時保持用戶界面響應(yīng)。
注意:RealTimeSource可以有效地處理不超過數(shù)百條數(shù)據(jù)記錄的數(shù)據(jù)源。
下圖演示了使用RealTimeSource綁定到動態(tài)數(shù)據(jù)的GridControl。
如果您的數(shù)據(jù)源中的記錄經(jīng)常更新(例如,每秒 20 000 次更新),可以考慮使用 組件。
將RealTimeSource與靜態(tài)數(shù)據(jù)一起使用不會導(dǎo)致任何性能改進(jìn)。
注意:RealTimeSource是數(shù)據(jù)感知控件和實(shí)際數(shù)據(jù)之間的一層。
在決定在應(yīng)用程序中使用 RealTimeSource 組件之前,請考慮以下限制。
支持以下通知類型。
您可以將任何數(shù)據(jù)感知控件綁定到 RealTimeSource,以GridControl為例。
要在 GridControl 中顯示實(shí)時數(shù)據(jù),請執(zhí)行以下操作。
C#
ObservableCollection<Data> Persons; //... DevExpress.Data.RealTimeSource myRealTimeSource = new DevExpress.Data.RealTimeSource(); myRealTimeSource.DataSource = Persons; myGridControl.ItemsSource = myRealTimeSource;
下面描述了其他RealTimeSource配置方案。
場景:指定哪些數(shù)據(jù)源屬性被傳遞給數(shù)據(jù)感知控件。
方法:使用屬性指定所需的數(shù)據(jù)源屬性。
C#
//A semicolon-separated list of data source property names myRealTimeSource.DisplayableProperties = "Id;Progress";
場景:忽略對單個屬性值的修改。
方法:將屬性設(shè)置為 true。將忽略對數(shù)據(jù)源項(xiàng)的修改,只有對數(shù)據(jù)源列表所做的修改才會傳遞給數(shù)據(jù)感知控件。
此示例演示如何使用 RealTimeSource 組件在 GridControl 中顯示快速變化的數(shù)據(jù)。
注意:此示例中的數(shù)據(jù)是出于演示目的隨機(jī)生成的。
MainWindow.xaml.cs
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)); } } }
MainWindow.xaml.vb
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
MainWindow.xaml
<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>
DevExpress WPF擁有120+個控件和庫,將幫助您交付滿足甚至超出企業(yè)需求的高性能業(yè)務(wù)應(yīng)用程序。通過DevExpress WPF能創(chuàng)建有著強(qiáng)大互動功能的XAML基礎(chǔ)應(yīng)用程序,這些應(yīng)用程序?qū)W⒂诋?dāng)代客戶的需求和構(gòu)建未來新一代支持觸摸的解決方案。 無論是Office辦公軟件的衍伸產(chǎn)品,還是以數(shù)據(jù)為中心的商業(yè)智能產(chǎn)品,都能通過DevExpress WPF控件來實(shí)現(xiàn)。
DevExpress技術(shù)交流群5:742234706 歡迎一起進(jìn)群討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)