TextControlBox.WinUI.JuliusKirsch
1.7.0
dotnet add package TextControlBox.WinUI.JuliusKirsch --version 1.7.0
NuGet\Install-Package TextControlBox.WinUI.JuliusKirsch -Version 1.7.0
<PackageReference Include="TextControlBox.WinUI.JuliusKirsch" Version="1.7.0" />
<PackageVersion Include="TextControlBox.WinUI.JuliusKirsch" Version="1.7.0" />
<PackageReference Include="TextControlBox.WinUI.JuliusKirsch" />
paket add TextControlBox.WinUI.JuliusKirsch --version 1.7.0
#r "nuget: TextControlBox.WinUI.JuliusKirsch, 1.7.0"
#:package TextControlBox.WinUI.JuliusKirsch@1.7.0
#addin nuget:?package=TextControlBox.WinUI.JuliusKirsch&version=1.7.0
#tool nuget:?package=TextControlBox.WinUI.JuliusKirsch&version=1.7.0
<div align="center"> <img src="images/Icon1.png" height="150px" width="auto"> <h1>TextControlBox-WinUI</h1> </div>
<div align="center"> <img src="https://img.shields.io/github/issues/FrozenAssassine/TextControlBox-WinUI.svg?style=flat"> <img src="https://img.shields.io/github/stars/FrozenAssassine/TextControlBox-WinUI.svg?style=flat"> <img src="https://img.shields.io/github/repo-size/FrozenAssassine/TextControlBox-WinUI?style=flat">
</div>
<br/>
🤔 What is TextControlBox?
TextControlBox is a powerful and highly customizable textbox control for WinUI 3 applications. It provides an advanced text editing experience with features like syntax highlighting for multiple programming languages, intuitive search and replace functionality, zooming, line numbering, and smooth scrolling. With support for undo/redo, customizable themes, and efficient performance.
📦 Download
NuGet Package: TextControlBox.WinUI.JuliusKirsch
❤️ Support my work
If you find TextControlBox useful and want to support its development:
🛠️ Features
- Basic Text Editing: Cut, copy, paste, undo, redo, and full text selection capabilities.
- Navigation & Selection:
- Go to a specific line.
- Select specific lines or the entire text.
- Scrolling & Zooming:
- Scroll to specific lines or pages.
- Smooth scrolling with mouse wheel acceleration, respects the Windows wheel settings.
- Diagonal scrolling on precision touchpads.
- Zoom in and out for better readability (Ctrl + wheel, touchpad pinch).
- Word Wrap:
- Long lines wrap at the control width instead of scrolling horizontally (
WordWrap). - Works with very large documents and very long lines.
- Long lines wrap at the control width instead of scrolling horizontally (
- Touch & Pen:
- Tap to place the cursor, double tap selects a word, triple tap selects the line.
- Long press selects a word and drags the selection, a normal drag scrolls, two fingers pinch to zoom.
- Input:
- IME composition (Japanese, Chinese, Korean), dead keys and the Windows emoji panel.
- Emojis and surrogate pairs are handled as one character for cursor movement and deletion.
- Syntax Highlighting:
- Built-in support for multiple programming languages.
- Easily toggle syntax highlighting on and off.
- Search & Replace:
- Multi highlight search
- Find and replace text with options for case sensitivity and whole-word matching.
- Customization Options:
- Show or hide line numbers.
- Customize font, theme, and cursor appearance.
- Configure spaces vs. tabs for indentation.
- Other Features:
- Drag & drop text support.
- Surround selected text with custom characters.
- Get cursor position and manage selections programmatically.
- Native AOT compatible.
Limits & Missing features
- 200 million lines of text (20 characters per line) and it started to consume around 20GB of ram, scrolling worked, but random freezes appeared (too much overhead).
- Syntaxhighlighting for multi line comments or similar only works, if both start and end characters are in the visible view. (Due to performance I only do such actions on the visible rendered text)
‼️Common Pitfalls & Performance Improvements
| Scenario | ❌Common Pitfall | ✅Recommended Approach | Notes |
|---|---|---|---|
| Getting/Setting Text | textbox.Text = someText |
Use LoadText(string) or LoadLines(IEnumerable<string>) if you do not want to record an undo step |
Text and SetText always record an undo step. Load methods bypass undo history by design. |
| Character Count | textbox.Text.Length |
textbox.CharacterCount() |
Uses spans internally; avoids temporary string allocations. |
| Accessing Lines | textbox.Text.Split("\n") |
textbox.Lines or textbox.NumberOfLines |
Avoids creating temporary string arrays. Lines exposes the internal list efficiently. |
| Word Count | Manual splitting or regex on Text |
textbox.WordCount() |
Uses spans and char iteration for allocation-free counting. |
| Saving Text to File | File.WriteAllText("file.txt", textbox.GetText()) |
File.WriteAllLines("file.txt", textbox.Lines) |
Writes lines directly; avoids allocating a single large string on the heap. |
| Text Search | Manually iterating or substring search | Use BeginSearch(word, wholeWord, matchCase) + FindNext() / FindPrevious() + EndSearch() |
Provides fast, internal search with highlights and efficient indexing. |
| Iterating Lines | foreach(var line in textbox.Text.Split('\n')) |
foreach(var line in textbox.Lines) |
Iterates without extra string allocations. |
| Replacing Text | Using GetText() and manually replacing strings |
Use ReplaceNext(replaceWord) or ReplaceAll(word, replaceWord) |
Efficient, allocation-free replacements with undo handling options. |
Tips:
TextandSetTextare convenient but always record an undo step; useLoadText/LoadLinesto avoid this.- Prefer
CharacterCount(),WordCount(),Lines, andNumberOfLinesfor performance-sensitive operations. - Use
BeginSearch/FindNext/FindPreviousfor searching instead of manual string operations. - Save large text efficiently with
File.WriteAllLines(textbox.Lines)rather thanGetText().
🏗️ Getting Started
Add TextControlBox to your WinUI 3 project and include the necessary namespace in your XAML or C# file.
using TextControlBoxNS;
Basic Usage
TextControlBox textBox = new TextControlBox();
textBox.LoadText("Hello, world!");
textBox.ShowLineNumbers = true;
textBox.EnableSyntaxHighlighting = true;
<details>
<summary><h2>🛠️ All properties and functions</h2></summary>
Text: Gets or sets the full content of the editor.SelectedText: Gets the currently selected text.CurrentSelection,CurrentSelectionOrdered: Provides selection metadata.HasSelection: Indicates if any text is currently selected.CursorPosition: Gets the current cursor position.CurrentLineIndex: Index of the line containing the cursor.NumberOfLines: Total number of lines in the editor.FontFamily: Gets or sets the font family.FontSize: Gets or sets the base font size.TextColor: Gets or sets the base text color (syntax highlighting colors take precedence).WordWrap: Gets or sets whether long lines wrap at the control width instead of scrolling horizontally.RenderedFontSize: Gets the final rendered font size.CornerRadius: Gets or sets the control's corner radius.RequestedTheme: Gets or sets the UI theme.Design: Gets or sets visual settings like line numbers and highlighting.ShowLineNumbers: Toggles line number visibility.ShowLineHighlighter: Toggles current line highlighting.EnableSyntaxHighlighting: Enables or disables syntax highlighting.SyntaxHighlighting: Gets or sets the current syntax highlighting language.LineEnding: Gets or sets the line ending mode.SpaceBetweenLineNumberAndText: Spacing between line numbers and text.ZoomFactor: Gets or sets the zoom factor.VerticalScroll,HorizontalScroll: Gets or sets scroll offsets.ScrollBarPosition: Gets or sets the position of both scrollbars.VerticalScrollSensitivity,HorizontalScrollSensitivity: Adjust scroll speed.SmoothScrolling: Enables or disables smooth scrolling for mouse wheel and touchpad.UseSpacesInsteadTabs: Enables space-based tabulation.NumberOfSpacesForTab: Sets number of spaces per tab.SearchIsOpen: Indicates whether the search panel is open.Lines: Gets all lines as strings.DoAutoPairing: Enables auto-pairing of brackets/quotes.AutoPairOnlyOnSelection: When enabled, auto-pairing only surrounds selected text instead of also completing typed brackets/quotes.ControlW_SelectWord: Enables Ctrl+W to select the current word.ContextFlyout: Gets or sets the context menu flyout.ContextFlyoutDisabled: Disables the context menu.IsReadOnly: Determines if the control is read-only.CursorSize: Gets or sets the cursor size.UndoRedoEnabled: Enables/disables undo/redo functionalityUndoBatching: Groups consecutive typing within a word into one undo step (like VS Code)IsGroupingActions: Gets whether grouping of undo redo is enabled or disabledBeginActionGroup: Starts the grouping of undo redo itemsEndActionGroup: Ends the grouping of undo redo itemsExecuteActionGroup(Action actionGroup): Runs all operations in the delegate as a single undo/redo stepSelectionScrollStartBorderDistance: Gets or sets the mouse distance from the text box edge that triggers auto-scroll during selectionShowWhitespaceCharacters: Gets or sets whether spaces and tabs are visually shown in the text box (e.g. as dots or arrows)ActualLineHeight,SingleLineHeight: Return the rendered height of a single line in pixelHighlightLineWhenNotFocused: Controls, whether the line is still highlighted when control is not focusedCanUndo: Gets whether undo could be executed.CanRedo: Gets whether redo could be executed.HighlightLinks: Gets or sets, whether links inside the text are highlighted and clickableFocus(FocusState state): Sets focus to the control.SelectLine(int line): Selects a specific line.SelectLines(int start, int count): Selects a range of lines.GoToLine(int line): Moves the cursor to a specific line.LoadText(string text, bool autodetectTabsSpaces = true): Loads text into the control without an undo step.SetText(string text): Sets the text content.LoadLines(IEnumerable<string> lines, bool autodetectTabsSpaces = true, LineEnding lineEnding = LineEnding.CRLF): Loads multiple lines without an undo step.Paste(): Pastes clipboard content.Copy(): Copies the selection to clipboard.Cut(): Cuts the selected text.GetText(): Returns the current content.SetSelection(int start, int length): Selects a specific text range.SelectAll(): Selects all text.Delete(): Deletes the selected text, or the character after the cursor if nothing is selected.ClearSelection(): Clears any text selection.Undo(): Undoes the last action.Redo(): Redoes the last undone action.ScrollLineToCenter(int line): Scrolls a line to center.ScrollOneLineUp(),ScrollOneLineDown(): Scrolls one line vertically.ScrollLineIntoView(int line): Brings a line into view.ScrollTopIntoView(),ScrollBottomIntoView(): Scrolls to top/bottom.ScrollPageUp(),ScrollPageDown(): Scrolls a full page.ScrollIntoViewHorizontally(): Scrolls horizontally into view.ScrollIntoViewHorizontallyCentered(): Centers the cursor column horizontally (useful for search matches, no-op in word wrap mode).GetLineText(int line): Returns the text of a line.GetLinesText(int startLine, int length): Returns a range of lines.SetLineText(int line, string text): Replaces the text of a line.DeleteLine(int line): Deletes a specific line.AddLine(int line, string text): Adds a new line at a position.AddLines(int start, string[] lines): Adds the array of lines at the given position (lines must not contain line breaks).SurroundSelectionWith(string text): Surrounds selection with a string.SurroundSelectionWith(string text1, string text2): Surrounds with prefix/suffix.DuplicateLine(int line, bool ignoreIsReadOnly = false): Duplicates the specified line.DuplicateCurrentLine(bool ignoreIsReadOnly = false): Duplicates the current line.ReplaceAll(string word, string replaceWord, bool matchCase, bool wholeWord, bool ignoreIsReadOnly = false): Replaces all matches.ReplaceNext(string replaceWord, bool ignoreIsReadOnly = false): Replaces the next match.FindNext(),FindPrevious(): Navigates search results.BeginSearch(string word, bool wholeWord, bool matchCase): Starts a search.EndSearch(): Ends the search.Unload(),Dispose(): Releases all resources when the control is closed for good (e.g. a closed tab). Calling it more than once is safe.ClearUndoRedoHistory(): Clears undo/redo history.GetCursorPosition(): Returns the cursor's screen position.GetLineFromPoint(Point point): Returns the line at the given point.SetCursorPosition(int lineNumber, int characterPos, bool scrollIntoView = true, bool autoClamp = true): Sets the cursor position.SelectSyntaxHighlightingById(SyntaxHighlightID languageId): Sets highlighting by ID.CalculateSelectionPosition(): Gets position info for selection.CharacterCount(): Returns character count.WordCount(): Returns word count.TextChanged: Event triggered when text changes.SelectionChanged: Event triggered on selection change.ZoomChanged: Event triggered when zoom changes.GotFocus,LostFocus,Loaded: Focus and lifecycle events.SyntaxHighlightings: Static dictionary of syntax languages.GetSyntaxHighlightingFromID(SyntaxHighlightID languageId): Gets highlighting language.GetSyntaxHighlightingFromJson(string json): Loads highlighting from JSON.RewriteTabsSpaces(int spaces, bool useSpacesInsteadTabs, bool ignoreIsReadOnly = false): Changes the current indentation of the text to a new indentation.DetectTabsSpaces(): Detects and returns the current indentation of the text as tuple </details>
🚀 Events
TextControlBox provides several events to handle user interactions:
TextChanged: Triggered when the text content changes.SelectionChanged: Fires when the user changes the selected text.ZoomChanged: Called when the zoom factor is adjusted.GotFocus/LostFocus: Handle focus changes.TextLoaded: Occurs when the TextControlBox finished loading the text.Loaded: Occurs when the TextControlBox finished loading and all components initializedTabsSpacesChanged: Occurs when the tabs or spaces change, from LoadLines/LoadText or from propertiesLineEndingChanged: Occurs when the line ending changes, from LoadLines/LoadText or from propertyLinkClicked: Occures when a link inside the textbox was clicked (contains the url as parameter)
🎨 Syntax Highlighting
TextControlBox includes built-in support for multiple languages:
- C#, C++, Java, Python, JavaScript, JSON, x86Assembly, HTML, CSS, SQL, Markdown, Batch, Config (Ini, Klipper -Styles), CSV, CSV Improved (colored columns), Log files, .gitignore, LaTex, PHP, QSharp, TOML, XML, G-Code, Lua, Hex, Generic (language independent: numbers, strings, comments, operators, dates, IPs, URLs, ...)
Enable syntax highlighting:
textBox.SelectSyntaxHighlightingById(SyntaxHighlightID.CSharp);
👨👩👧👦 Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue.
🧾 License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0-windows10.0.19041 is compatible. net10.0-windows was computed. |
-
net9.0-windows10.0.19041
- Collections.Pooled (>= 1.0.82)
- Microsoft.Graphics.Win2D (>= 1.4.0)
- Microsoft.Windows.SDK.BuildTools (>= 10.0.28000.2705)
- Microsoft.WindowsAppSDK (>= 2.5.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on TextControlBox.WinUI.JuliusKirsch:
| Repository | Stars |
|---|---|
|
kyoyama-kazusa/Sudoku
A sudoku solver using brute forces and logical techniques.
|
|
|
Storik4pro/cdpiui
Modern UI for Deep Packet Inspection bypass utils (Windows 10/11)
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.7.0 | 39 | 10/24/2026 |
| 1.6.2 | 866 | 2/2/2026 |
| 1.6.1 | 250 | 1/23/2026 |
| 1.6.0 | 278 | 1/8/2026 |
| 1.5.1 | 394 | 12/15/2025 |
| 1.5.0 | 433 | 11/27/2025 |
| 1.4.0 | 375 | 11/6/2025 |
| 1.3.0 | 486 | 8/22/2025 |
| 1.2.0 | 270 | 8/21/2025 |
| 1.1.5 | 490 | 4/16/2025 |
| 1.1.4 | 347 | 3/17/2025 |
| 1.1.3 | 283 | 3/14/2025 |
| 1.1.2 | 339 | 3/11/2025 |
| 1.1.1 | 376 | 3/3/2025 |
| 1.1.0-alpha.3 | 185 | 2/28/2025 |
| 1.1.0-alpha.2 | 195 | 2/22/2025 |
| 1.1.0-alpha | 264 | 2/10/2025 |
| 1.0.0 | 484 | 8/1/2023 |
New: Word wrap (WordWrap), also for very large documents and very long lines
New: Touch and pen support (tap, double/triple tap, long press selection, pinch zoom)
New: IME input (Japanese, Chinese, Korean) and full emoji support
New: Smooth scrolling, wheel acceleration, diagonal touchpad scrolling, touchpad pinch zoom
New: Batched undo (UndoBatching), Dispose(), Delete(), GetLineFromPoint(), ScrollIntoViewHorizontallyCentered()
New: Native AOT compatible, log file and generic language independent syntax highlighting
Improved: Much faster editing of long lines and lower undo memory usage
Improved: Syntax highlighting accuracy and performance for all languages
Changed: JSON languages load via System.Text.Json, Newtonsoft.Json dependency removed
Changed: AddLines throws for lines containing line breaks
Fixed: Many undo/redo, selection, cursor, word wrap, zoom and scrolling bugs
Fixed: Memory leaks after closing tabs, theme changes, double right click menu
Full changelog: https://github.com/FrozenAssassine/TextControlBox-WinUI/blob/master/CHANGELOG.md