This example demostrates how to call the BeginDataUpdate and EndDataUpdate methods in an MVVM application. These methods allow you to accumulate changes and update data within the GridControl in one action.
Follow these steps to use the methods in your application:
1. Create a custom service that allows you to call the GridControl methods.
...
public interface ICustomService {
void BeginUpdate();
void EndUpdate();
}
class CustomService : ServiceBase, ICustomService {
GridControl ActuaGridControl { get { return AssociatedObject as GridControl; } }
//...
public void BeginUpdate() {
ActuaGridControl.BeginDataUpdate();
}
public void EndUpdate() {
ActuaGridControl.EndDataUpdate();
}
}
...
2. Add the service to your View and assosiate this service with the GridControl.
<dxg:GridControl>
<mvvm:Interaction.Behaviors>
<local:CustomService />
</mvvm:Interaction.Behaviors>
</dxg:GridControl>
...
3. Access to the service at the View Model level. If you inherit your View Model class from ViewModelBase, you can access to the service as follows:
public class ViewModel : ViewModelBase {
//...
public ICustomService CustomService { get { return this.GetService<ICustomService>(); } }
[Command]
public void UpdateSource() {
CustomService.BeginUpdate();
foreach(DataItem item in Source) {
item.Value = random.Next(Source.Count);
}
CustomService.EndUpdate();
}
}
If you use Generated View Models or Custom View Models, refer to the following topics:
- CustomService.cs (VB: CustomService.vb)
- ViewModel.cs (VB: ViewModel.vb)
- MainWindow.xaml (VB: MainWindow.xaml)
- WPF Data Grid - Process Data Updates
- Data Grid for WPF - Update Data in a Separate Thread
- Data Grid for WPF - Refresh the Data Grid on a Timer
- WPF MVVM Framework - Create a Custom Service
(you will be redirected to DevExpress.com to submit your response)