# Getting Started with WPF (.NET 5 and better)

> This article shows how to use the TX Text Control WPF.TextControl class within a .NET 6 application in Visual Studio 2022.

- **Author:** Bjoern Meyer
- **Published:** 2022-09-01
- **Modified:** 2025-11-16
- **Description:** This article shows how to use the TX Text Control WPF.TextControl class within a .NET 6 application in Visual Studio 2022.
- **3 min read** (467 words)
- **Tags:**
  - WPF
  - .NET 6
  - Getting Started
- **LLMs.txt URL:** https://www.textcontrol.com/blog/2022/09/01/getting-started-with-wpf-net-5-and-better/llms.txt
- **LLMs-full.txt URL:** https://www.textcontrol.com/blog/2022/09/01/getting-started-with-wpf-net-5-and-better/llms-full.txt
- **Canonical URL:** https://www.textcontrol.com/blog/2022/09/01/getting-started-with-wpf-net-5-and-better/

---

The following tutorial shows how to create a .NET Framework WPF Application that uses the WPF.TextControl class.

### Creating the Project

1. Open Visual Studio 2022 and create a new project. Select *C#* or *Visual Basic* from the *Languages* drop-down list, *Windows* from the *Platform list* and *Desktop* as the *Project Type.* Find the project template *WPF Application* and confirm with *Next*.
    
    ![Windows Forms](https://s1-www.textcontrol.com/assets/dist/blog/2022/09/01/k/assets/visual_studio1.webp "Windows Forms")
2. Specify a project name confirm with *Next*.
3. Select your preferred *Framework* version such as *.NET 6 (Long-term support)* and confirm with *Create*.

### Adding the Control

1. Select the project in the *Solution Explorer* and click *Project -> Manage NuGet Packages...* from the main menu.
2. Select *Text Control Offline Packages* as the *Package source* and click *Browse*.
3. Select **TXTextControl.TextControl.WPF.SDK** and click *Install*.
    
    ![Windows Forms](https://s1-www.textcontrol.com/assets/dist/blog/2022/09/01/k/assets/visual_studio2.webp "Windows Forms")
4. In the XAML view, replace the *Grid* with a *DockPanel* control as shown in the below screenshot:
    
    ![Windows Forms](https://s1-www.textcontrol.com/assets/dist/blog/2022/09/01/k/assets/visual_studio3.webp "Windows Forms")

### Connecting the Controls

In the next steps, the order in which the controls are added to the Window is important.

1. Find the *TX Text Control 31.0* tab in the *Toolbox*.
    
    ![Windows Forms](https://s1-www.textcontrol.com/assets/dist/blog/2022/09/01/k/assets/visual_studio1a.webp "Windows Forms")
2. Double-click the *ButtonBar* in the *Toolbox* to add it to the Window.
    
    > **Getting an error?**
    > 
    > For the first element, you will receive a warning similar to the screenshot below. To solve this, select the project in the *Solution Explorer* and click *Rebuild Solution*.
    > 
    > ![Windows Forms](https://s1-www.textcontrol.com/assets/dist/blog/2022/09/01/k/assets/visual_studio4.webp "Windows Forms")
    
    Make sure that the Window is selected and not the inserted *ButtonBar* before adding the following elements.
3. Repeat this for the *RulerBar*, *StatusBar*, a second *RulerBar* and finally *TextControl*.
4. In the XAML, remove the *Height* and the *Width* properties for all added elements.
5. Name all elements according to the following screenshot: *buttonBar1*, *rulerBar1*, *statusBar*, *rulerBar2* and *textControl1*.
    
    ![Windows Forms](https://s1-www.textcontrol.com/assets/dist/blog/2022/09/01/k/assets/visual_studio5.webp "Windows Forms")
6. In the XAML, add the *Loaded="textControl1\_Loaded"* event handler to the *TextControl* element as a parameter, so that the line looks like this:
    
    ```
    <WPF:TextControl Name="textControl1" Loaded="textControl1_Loaded"
    ButtonBar="buttonBar1" StatusBar="statusBar1" RulerBar="rulerBar1" VerticalRulerBar="rulerBar2"/>
    ```
    
    Right-click on *textControl1\_Loaded* and choose *Go To Definition* from the opened context menu. Add the following code to the event handler:
    
    ```
    private void textControl1_Loaded(object sender, RoutedEventArgs e)
    {
    textControl1.Focus();
    }
    ```
    
    In the XAML, set the *DockPanel.Dock* property of the *RulerBar* to *Left*, the *HorizontalAlignment* to *Left* and the *VerticalAlignment* to *Stretch*. The full *DockPanel* XAML code should look like this:
    
    ```
    <DockPanel>
    <WPF:ButtonBar x:Name="buttonBar1" />
    <WPF:RulerBar x:Name="rulerBar1" />
    <WPF:StatusBar x:Name="statusBar1"/>
    <WPF:RulerBar x:Name="rulerBar2" DockPanel.Dock="Left" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
    <WPF:TextControl Name="textControl1" Loaded="textControl1_Loaded"
    ButtonBar="buttonBar1" StatusBar="statusBar1" RulerBar="rulerBar1" VerticalRulerBar="rulerBar2"/>
    </DockPanel>
    ```
7. Now, press F5 to compile and start the application.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub](https://www.textcontrol.com/blog/2023/01/08/official-tx-text-control-net-sample-applications-are-now-hosted-on-github/llms.txt)
- [Getting Started with WPF (.NET Framework)](https://www.textcontrol.com/blog/2022/09/01/getting-started-with-wpf-net-framework/llms.txt)
- [Getting Started with Windows Forms (.NET 5 and better)](https://www.textcontrol.com/blog/2022/09/01/getting-started-with-windows-forms-net-5-and-better/llms.txt)
- [Windows Forms and WPF Comeback: .NET 6 and 7. Our Commitment to Windows Applications](https://www.textcontrol.com/blog/2022/08/17/windows-forms-and-wpf-comeback-net-6-and-7-our-commitment-to-windows-applications/llms.txt)
- [Visual Studio 2022 and .NET 5, 6 and 7 (Preview) Support and Strategy](https://www.textcontrol.com/blog/2022/08/11/visual-studio-2022-net-5-6-7-support-and-strategy/llms.txt)
- [New Getting Started Article Hub Launched](https://www.textcontrol.com/blog/2022/07/11/new-getting-started-article-hub-launched/llms.txt)
- [Sneak Peek 31.0: Signature Fields](https://www.textcontrol.com/blog/2022/05/27/sneak-peek-310-signature-fields/llms.txt)
- [Sneak Peek 31.0: Full .NET 6 Visual Studio Designer Support](https://www.textcontrol.com/blog/2022/05/27/sneak-peek-31-full-net-6-visual-studio-designer-support/llms.txt)
