How to create a Custom Service

  • 3 minutes to read

Follow the two steps outlined below to create a custom service.

  • Create a service interface that will be available from the View Model layer.
  • Create a ServiceBase descendant (or a ViewServiceBase descendant) that implements the service interface.

The ServiceBase class is descended from the Behavior<FrameworkElement> class. Please review the following documentation topic to learn which properties and methods the Behavior<T> class provides and how to use them when creating a Behavior descendant: How to: Create a Custom Behavior.

The example below demonstrates how to create a custom service (a ServiceBase descendant) that provides the capability to show a message box with text defined in Xaml.

using System.Windows.Controls;

namespace Example.View {
    public partial class MainView : UserControl {
        public MainView() {
            InitializeComponent();
        }
    }
}