Search code examples
c#wpfxamltextboxrichtextbox

Why does the ToolBar Command "ToggleBold" has no function in an Regular TextBox?


So Ive got an ToolBar and wanted to Bold my Text, with an RichTextBox its working but not with an normal regular TextBox. Could someone tell me why only RichTextBox is working and not the normal one? And how could I get the normal TextBox to work because the RichTextBox is impractical.

My Code looks like that:

<DockPanel>
        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar>
                <Button Command="Cut" ToolTip="Cut selection to Windows Clipboard.">
                </Button>
                <Button Command="Copy" ToolTip="Copy selection to Windows Clipboard.">
                </Button>
                <Button Content="Hallo" Command="ToggleBold" ToolTip="Paste from Windows Clipboard.">
                   
                </Button>
                <Separator />
                <Label>Font size:</Label>
                <ComboBox>
                    <ComboBoxItem>10</ComboBoxItem>
                    <ComboBoxItem IsSelected="True">12</ComboBoxItem>
                    <ComboBoxItem>14</ComboBoxItem>
                    <ComboBoxItem>16</ComboBoxItem>
                </ComboBox>
            </ToolBar>
        </ToolBarTray>
        <TextBox AcceptsReturn="True" />
    </DockPanel>

Solution

  • The TextBox does not support formatting related commands like ToggleBold (Ctrl+B).

    Control Spellchecking Context Menu Formatting commands FlowDocument content
    TextBox Yes Yes No No
    RichTextBox Yes Yes Yes Yes

    See the documentation: TextBox or RichTextBox?