Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am targeting the .NET 6.0 framework in a new WPF project and would like to use a RichTextBox control (RTB). I understand the RTB outputs its content as a FlowDocument.

Code samples showing how to work with a FlowDocument in earlier frameworks use the System.Windows.Documents namespace. Microsoft's documentation for the FlowDocument Class refers to this namespace in the definition.

I can't find a reference/Nuget package for adding this dependency in .NET 6.0. Can someone please tell me how to find/add this?

What I have tried:

Looked for code samples and in Microsoft documentation for FlowDocument Class
Posted
Updated 6-Mar-22 6:11am
Comments
Maciej Los 6-Mar-22 12:01pm    
Maybe you need complete control? See: NuGet Gallery | C1.WPF.RichTextBox 6.0.20213.167[^]

1 solution

Figured it out. I added Microsoft.WindowsDesktop.App.WPF as a dependency in my Class Library. In the .csproj file this changed the PropertyGroup from:
<PropertyGroup>
  <TargetFramework>net6.0</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>enable</Nullable>
</PropertyGroup>

to:
<PropertyGroup>
  <TargetFramework>net6.0-windows</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>enable</Nullable>
  <UseWPF>true</UseWPF>
</PropertyGroup>

In my ViewModel I can now refer to the System.Windows.Documents namespace through:
using System.Windows.Documents;

and create a FlowDocument object via:
C#
FlowDocument flowDocument = new();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900