DispatcherService

The DispatcherService is an IDispatcherService implementation that allows you to perform actions in a ViewModel using the Dispatcher.

Getting Started with DispatcherService

Use the DispatcherService to perform an action in a ViewModel using the Dispatcher. Add the service to the view’s dxmvvmi:Interaction.Behaviors.

<UserControl
    xmlns:dxmvvmi="using:DevExpress.WinUI.Mvvm.UI.Interactivity"
    xmlns:dxmvvm="using:DevExpress.WinUI.Mvvm.UI"
    xmlns:ViewModel="using:WinUIApp.ViewModel" ...>
    <UserControl.DataContext>
        <ViewModel:ViewModel />
    </UserControl.DataContext>
    <dxmvvmi:Interaction.Behaviors>
        <dxmvvm:DispatcherService />
    </dxmvvmi:Interaction.Behaviors>
        ...
</UserControl>

Use the BeginInvoke method to perform the required actions. The example below uses the DispatcherService to execute the CalcCore method defined in the View Model.

public class ViewModel {
    protected IDispatcherService DispatcherService { get { return this.GetService<IDispatcherService>(); } }
    ...
    void CalcCore() {
        ...
        DispatcherService.BeginInvoke(() => { ... });
        ...     
    }
    ...
}

The DispatcherService has the following properties:

  • DispatcherPriority - gets or sets the DispatcherService’s Dispatcher priority by which operations can be invoked by the Dispatcher.
  • Delay - gets or sets the time delay (a TimeSpan object) before invoking the DispatcherService’s BeginInvoke method.