# WPF RichTextBox Events

This topic covers the specific events exposed by the **RadRichTextBox** control.

The **RadRichTextBox** control raises the following specific events:

* **CommandError** - occurs when an error gets thrown while executing a command. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * A **CommandErrorEventArgs** object.

* **CommandExecuted** - occurs after a command gets executed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * A **CommandExecutedEventArgs** object. These arguments allow you to access the command to be executed and its command parameter.

* **CommandExecuting** - occurs before a command gets executed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * A **CommandExecutingEventArgs** object. These arguments allow you to access the command to be executed and its command parameter and to cancel the command execution.
  > There is an SDK example demonstrating how you can customize the behavior of the commands using the above-listed events: [Customize Commands SDK example](https://github.com/telerik/xaml-sdk/tree/master/RichTextBox/CustomizeCommands)

* **CurrentEditingStyleChanged** - occurs when the current editing style changes. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object

* **CurrentParagraphStyleChanged** - occurs when the position of the caret goes to another paragraph. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **CurrentSpanStyleChanged** - occurs when the position of the caret goes to another word. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **CurrentVisiblePageChanged** - occurs when the current page has changed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **DocumentArranged** - occurs when the current document has been arranged. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **DocumentChanged** - occurs when the current document has been changed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **DocumentChanging** - occurs before the current document gets changed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **DocumentContentChanged** - occurs when the content of the current document has changed. This is an aggregated event, which is raised not more frequently than the value specified in RadDocument.DocumentContentChangedInterval property for performance reasons. The default value of DocumentContentChangedInterval is 30ms.

The event handler receives two arguments:

```
* The sender argument contains the __RadRichTextBox__. This argument is of type object, but can be cast to the __RadRichTextBox__ type.
* An __EventArgs__ object.
```

* **DocumentLayoutModeChanged** - occurs when the layout mode of the current document has changed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **HyperlinkClicked** - occurs when a hyperlink inside the document is clicked. The event handler receives two arguments:

  * The sender argument contains the **Span** containing the hyperlink's content. This argument is of type object, but can be cast to the **Span** type.
  * A **HyperlinkClickedEventArgs** object. This argument exposes the link through `Url` and provides the target through `HyperlinkTarget`.

  Set `Handled` to `true` to cancel navigation. The `URL` property was renamed to `Url`; update applications that use the old property name. `HyperlinkClickedEventArgs` also inherits `IsTrustedUrl` from `HyperlinkClickedEventArgsBase`. Set it to `true` to allow a URL that the validator would otherwise reject. Absolute HTTP, HTTPS, and mailto URLs can be trusted by default when they pass the pattern and scheme checks.

  **Prompting that the clicked linked may be unsafe and allows it to cancel the navigation action**

  ```C#
  private void RadRichTextBox_HyperlinkClicked(object sender, HyperlinkClickedEventArgs e)
  {
      var link = e.URL;
      if (link.EndsWith("exe"))
      {
          e.Handled = true;
          MessageBoxResult Result = MessageBox.Show("You are about to open an executable file. Do you want to proceed", "Possible unsafe link", MessageBoxButton.YesNo, MessageBoxImage.Question);

          if (Result == MessageBoxResult.Yes)
          {
              Process.Start(new ProcessStartInfo()
              {
                  FileName = link,
                  UseShellExecute = true
              });
          }
      }
  }
  ```

  After the applicable document- and editor-specific event handlers run, `HyperlinkManager.HyperlinkClicked` runs if none set `Handled` to `true`. The shared event uses the same event arguments and sends the originating component as `sender`. Since the event is static, unsubscribe when the handler owner has a shorter lifetime than the application. See [Handling hyperlink requests in the hyperlink article](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/document-elements-hyperlink).

* **IsReadOnlyChanged** - occurs when **IsReadOnly** value has changed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **ScaleFactorChanged** - occurs when the **ScaleFactor** value has changed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.
  * An **EventArgs** object.

* **SelectedLayoutBoxChanged** - occurs when the current layout box gets changed. The event handler receives two arguments:
  * The sender argument contains the **RadRichTextBox**. This argument is of type object, but can be cast to the **RadRichTextBox** type.

  * A **SelectedLayoutBoxChangedEventArgs** object.

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/getting-started/getting-started)
* [Telerik UI for WPF API Reference](https://docs.telerik.com/devtools/wpf/api/)
