---
title: 'WPF Scrolling TextBox'
url: 'https://www.dowerchin.com/blog/wpf-scrolling-textbox'
markdown: 'https://www.dowerchin.com/blog/wpf-scrolling-textbox.md'
date: '2024-01-31'
description: 'In my recent adventures in PowerShell scripting, I needed to create a GUI for my large script. This was inevitable, since my console input prompts started to become extensive and unwieldy. In my course of GUI development I found Windows Presentation Foundation (WPF) to be a good way to build a UI w…'
taxonomy:
  category:
    - Powershell
  tag:
    - PowerShell
---

# WPF Scrolling TextBox

In my recent adventures in PowerShell scripting, I needed to create a GUI for my large script. This was inevitable, since my console input prompts started to become extensive and unwieldy. In my course of GUI development I found Windows Presentation Foundation (WPF) to be a good way to build a UI with Visual Studio. What's a little bit unclear, is how to work with some of the nuances of the TextBox control and interactiing with it in PowerShell.

Here are some notes.

1. It's important to give your TextBox (or any control) a name, ie tbConsole.
2. Making a TextBox control scrollable is a bit buried in Visual Studio's designer, it wasn't obvious when looking at the properties panel. The default view in the properies panel is "Category", and I didn't see anything related to scrolling. When I changed to "Name", I was able to scroll down and find a checkbox for **ScrollViewer.CanContentScroll**. But this doesn't control how the scrollbars should appear, if I use the search option in the Properties panel, I can search for "scroll", and I was able to find the **HorizontalScrollBarVisibility** and **VerticalScrollBarVisibility** options which I can turn to **Auto**, **Hidden** or **Disabled**.
3. To clear the TextBox, I can use the following command in PowerShell: ```
    $tbConsole.Clear()
    ```
4. If you want to add carraige returns to text you are putting into the TextBox you do the following: ```
    $tbConsole.AppendText("SOME TEXT HERE`r`n")
    ```

---

## Navigation

- Parent: [Home](https://www.dowerchin.com/index.md)
- Previous: [Python: Creating Folders and Modifying their Dates](https://www.dowerchin.com/blog/python-creating-folders-and-modifying-their-dates.md)
- Next: [Fixing External Keyboards for Macs](https://www.dowerchin.com/blog/fixing-external-keyboards-for-macs.md)
