RichTextBox
in namespace DotVVM.BusinessPack.Controls
Renders a RichTextBox control similar to HTML <textarea> element with rich text editing capabilities.
Usage & Scenarios
RichTextBox edits formatted HTML. Use its default formatting commands or choose the commands available to the author.
Sample 1: Edit an announcement
Bind Html to the document, not its plain text. Edit the announcement to see the HTML as text below the editor. Changed counts changes, and Enabled lets you lock the draft without clearing it.
If you publish user-authored HTML, sanitize it on the server before rendering it as markup.
<dot:CheckBox Checked="{value: Editing}" Text="Allow editing" />
<bp:RichTextBox Html="{value: Announcement}" Enabled="{value: Editing}"
Changed="{command: Changes = Changes + 1}" />
<p>Changes: {{value: Changes}}</p>
<pre>{{value: Announcement}}</pre>
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.RichTextBox.sample1
{
public class ViewModel : DotvvmViewModelBase
{
public string Announcement { get; set; } = "<p>The library opens at <strong>nine</strong>.</p>";
public bool Editing { get; set; } = true;
public int Changes { get; set; }
}
}
Sample 2: Choose formatting commands
A nonempty Toolbar replaces the default command set. Group related rtb: commands with CommandGroup and use AlignToRight to separate the cleanup action. Select text in the editor to try the commands.
Use ButtonText or ButtonIcon to change a formatting button, and properties such as UriEditorLabel to change a command's popup. Other built-in commands cover paragraph styles, alignment, images, tables, and undo/redo.
<bp:RichTextBox Html="{value: Instructions}">
<Toolbar>
<rtb:CommandGroup>
<rtb:BoldCommand ButtonText="Bold" />
<rtb:ItalicCommand />
<rtb:BulletedListCommand />
<rtb:HyperlinkCommand UriEditorLabel="Reference URL" SaveButtonText="Apply" />
</rtb:CommandGroup>
<rtb:CommandGroup AlignToRight="true">
<rtb:ClearFormattingCommand ButtonText="Clear formatting" />
</rtb:CommandGroup>
</Toolbar>
</bp:RichTextBox>
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.RichTextBox.sample2
{
public class ViewModel : DotvvmViewModelBase
{
public string Instructions { get; set; } = "<p>Bring a notebook and a pencil.</p>";
}
}
Properties
| Name | Type | Description | Notes | Default Value | |
|---|---|---|---|---|---|
| ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
| DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
| Enabled | Boolean | Gets or sets a value indicating whether the editor's content can be modified. |
attribute
static value
bindable
|
True | |
| Html | String | Gets or sets the HTML contents of the editor. |
attribute
bindable
|
null | |
| ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
| IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
static value
bindable
|
True | |
| InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
| Toolbar | List<CommandGroup> | Gets or sets a collection of available commands organized in groups. |
inner element
static value
default
|
null | |
| Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
static value
bindable
|
True |
Events
| Name | Type | Description | |
|---|---|---|---|
| Changed | Command | Gets or sets the command triggered when the control text (or value) is changed. |