Skip to main content
A newer version of this page is available. .

DispatcherService Class

A UI service that allows you to use the DispatcherQueue to perform actions in a ViewModel.

Namespace: DevExpress.WinUI.Core

Assembly: DevExpress.WinUI.Core.v22.1.dll

NuGet Package: DevExpress.WinUI

Declaration

public class DispatcherService :
    UIServiceBase,
    IDispatcherService

Remarks

Run Demo: UI Services Module in the WinUI MVVM Demo

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

See Also