DispatcherService Class
In This Article
A UI service that allows you to use the DispatcherQueue to perform actions in a ViewModel.
Namespace: DevExpress.WinUI.Core
Assembly: DevExpress.WinUI.Core.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
public class DispatcherService :
UIServiceBase,
IDispatcherService
#Remarks
The following code sample adds DispatcherService to the view:
<UserControl
xmlns:dx="using:DevExpress.WinUI.Core"
xmlns:ViewModel="using:WinUIApp.ViewModel" ...>
<UserControl.DataContext>
<ViewModel:ViewModel />
</UserControl.DataContext>
<dx:Interaction.Behaviors>
<dx:DispatcherService />
</dx:Interaction.Behaviors>
<!-- Or: -->
<dx:Interaction.Behaviors>
<dx:DispatcherService ServiceClient="{x:Bind ViewModel}"/>
</dx:Interaction.Behaviors>
...
</UserControl>
Use the InvokeAsync method to perform the required actions.
public class ViewModel : ViewModelBase {
protected IDispatcherService DispatcherService => GetUIService<IDispatcherService>();
...
async void Calc() {
...
await DispatcherService.InvokeAsync(() => { ... });
...
}
}
#Implements
#Inheritance
See Also