Aligning a Single Line vs the Whole Paragraph (WPF)

    A recurring requirement in signature blocks, address blocks, and other short multi-line snippets is aligning one line, for example a name, independently from the lines around it, for example a title and a phone number underneath. Clicking the alignment toolbar button while the caret sits in one of those lines can appear to move every line at once, which looks like a defect the first time a developer runs into it. The behavior is standard HTML, and a single editor option controls it.

    Why it happens: alignment is block-level in HTML

    In HTML, text-align applies to a block-level container, <p>, <div>, <li>. It does not align an arbitrary "visual line". If three lines of text live inside a single <p> joined by <br>, setting text-align: center on that paragraph centers all three lines, because all three share the same block. To align only one of those lines, that line has to be its own block.

    <!-- One paragraph, three lines: align centers every line -->
    <p style="text-align:center">Sarah Lee<br>VP of Customer Success<br>+1 555 0100</p>
    
    <!-- Three paragraphs: each can be aligned independently -->
    <p style="text-align:center">Sarah Lee</p>
    <p>VP of Customer Success</p>
    <p>+1 555 0100</p>

    Same visible text. Different DOM. Different alignment behavior. The question becomes: when the user presses Enter at the end of a line, do you want the editor to produce a new block, or a soft line break? This is exactly the same MSHTML content model the WinForms edition sits on, so the answer is the same option under the same namespace.

    The one option that controls it: EnterKeyResponse

    Options.EnterKeyResponse takes one of two values from the EnterKeyResponses enum in SpiceLogic.HtmlEditor.Abstractions, the same namespace and the same enum the WinForms edition uses:

    EnterKeyResponses.Paragraph - Enter starts a new paragraph; the editor emits </p><p>. Each line becomes its own block, so the alignment toolbar buttons affect only the paragraph containing the caret. This is what most users expect, and it is the recommended default for a signature-block or template designer.

    EnterKeyResponses.LineBreak - Enter inserts a soft <br> inside the current paragraph. Everything typed stays inside one block, so the alignment buttons apply to the whole block at once. This is closer to a plain text-editor feel and useful for single-paragraph composer fields like reply boxes or short subject-line entries.

    // Per-line alignment is what a signature-block designer needs:
    NoteEditor.Options.EnterKeyResponse =
        SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.Paragraph;
    
    // Force single-block behavior (Enter = <br>, alignment is paragraph-wide):
    NoteEditor.Options.EnterKeyResponse =
        SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.LineBreak;
    ' Per-line alignment is what a signature-block designer needs:
    NoteEditor.Options.EnterKeyResponse =
        SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.Paragraph
    
    ' Force single-block behavior (Enter = <br>, alignment is paragraph-wide):
    NoteEditor.Options.EnterKeyResponse =
        SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.LineBreak

    Fixing legacy templates: a single line trapped inside a paragraph

    Some legacy templates have signature blocks already saved as one <p> with <br> separators. To align only the middle line, the user splits that paragraph so the middle line becomes its own block:

    1. Place the caret at the start of the line that should be aligned and press Enter (with EnterKeyResponse = Paragraph).
    2. Place the caret at the end of that line and press Enter again.
    3. With the caret still on the now-isolated line, click the alignment toolbar button.

    The middle line is now its own <p> and is the only one affected by the alignment command.

    Letting the end user pick the mode

    Expose a single checkbox in your host application's preferences, "Treat Enter as a line break (single paragraph mode)", and bind it to the option. The change applies to future Enter presses only; existing content is not rewritten:

    <CheckBox x:Name="ChkUseLineBreaks"
              Content="Treat Enter as a line break (single paragraph mode)"
              Checked="ChkUseLineBreaks_CheckedChanged"
              Unchecked="ChkUseLineBreaks_CheckedChanged" />
    private void ChkUseLineBreaks_CheckedChanged(object sender, RoutedEventArgs e)
    {
        NoteEditor.Options.EnterKeyResponse = ChkUseLineBreaks.IsChecked == true
            ? SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.LineBreak
            : SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.Paragraph;
    }
    Private Sub ChkUseLineBreaks_CheckedChanged(sender As Object, e As RoutedEventArgs)
        If ChkUseLineBreaks.IsChecked = True Then
            NoteEditor.Options.EnterKeyResponse = SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.LineBreak
        Else
            NoteEditor.Options.EnterKeyResponse = SpiceLogic.HtmlEditor.Abstractions.EnterKeyResponses.Paragraph
        End If
    End Sub

    The result

    A signature block built this way has each line in its own paragraph, with alignment applied per line, the way most users expect it to work, in both the WinForms and WPF editions.

    Ask your AI to do this

    Let your assistant do this for you. With the SpiceLogic MCP server connected, paste this into Claude Code, Cursor, or VS Code Copilot in agent mode.

    Using the SpiceLogic WPF HTML Editor already referenced in my project, give my template designer control over whether Enter starts a new paragraph or only a soft line break, by adding a CheckBox labeled Treat Enter as a line break bound through its Checked and Unchecked events to Options.EnterKeyResponse, switching between EnterKeyResponses.Paragraph and EnterKeyResponses.LineBreak from the SpiceLogic.HtmlEditor.Abstractions namespace. Use this so a three-line signature block, a name, a title, and a phone number, can have each line aligned independently once it lives in its own paragraph, instead of all three sharing one alignment because they sit inside a single paragraph joined by line breaks. Confirm the real EnterKeyResponses enum values and namespace with the SpiceLogic MCP tools before writing any code.

    Last updated on Aug 10, 2026

    Put this into practice.

    WPF HTML Editor Control ships with free C# and VB.NET sample projects and a 14-day evaluation.

    Prefer a guided look? Book a free live demo with our engineers - live on Zoom or Teams, never a chatbot.