Back to Devexpress

RichEditControl.ReplaceService<T>(T) Method

wpf-devexpress-dot-xpf-dot-richedit-dot-richeditcontrol-dot-replaceservice-1-x28-0-x29.md

latest2.9 KB
Original Source

RichEditControl.ReplaceService<T>(T) Method

Performs a service substitution.

Namespace : DevExpress.Xpf.RichEdit

Assembly : DevExpress.Xpf.RichEdit.v25.2.dll

NuGet Package : DevExpress.Wpf.RichEdit

Declaration

csharp
public T ReplaceService<T>(
    T newService
)
    where T : class
vb
Public Function ReplaceService(Of T As Class)(
    newService As T
) As T

Parameters

NameTypeDescription
newServiceT

A service of the specified type that will be registered.

|

Type Parameters

Name
T

Returns

TypeDescription
T

Previously registered service of the specified type, or null ( Nothing in Visual Basic) if the service does not exist.

|

Remarks

Use the ReplaceService<T> method instead of the RichEditControl.GetService -> RichEditControl.RemoveService -> RichEditControl.AddService method sequence.

Example

View Example

csharp
void richEditControl1_Loaded(object sender, RoutedEventArgs e) {
    ReplaceRichEditCommandFactoryService(richEditControl1);
}

void ReplaceRichEditCommandFactoryService(RichEditControl control)
{
    IRichEditCommandFactoryService service = control.GetService<IRichEditCommandFactoryService>();
    control.ReplaceService<IRichEditCommandFactoryService>(new CustomRichEditCommandFactoryService(control, service));
}
vb
Private Sub richEditControl1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ReplaceRichEditCommandFactoryService(richEditControl1)
End Sub

Private Sub ReplaceRichEditCommandFactoryService(ByVal control As RichEditControl)
    Dim service As IRichEditCommandFactoryService = control.GetService(Of IRichEditCommandFactoryService)()
    control.ReplaceService(Of IRichEditCommandFactoryService)(New CustomRichEditCommandFactoryService(control, service))
End Sub

See Also

RichEditControl Class

RichEditControl Members

DevExpress.Xpf.RichEdit Namespace