dotnet / dotnet/wpf

WPF flow document TextRange doesn't replace existing content right

Open
#10,822 0 comments 1 reaction 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

## Current Situation

When writing two or more [``](https://learn.microsoft.com/en-us/dotnet/api/system.windows.documents.section) elements to a [`TextRange`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.documents.textrange) object, supposed to replace the **whole flow document**, existing [``](https://learn.microsoft.com/en-us/dotnet/api/system.windows.documents.section) objects in a flow document control are not getting replaced. Instead, the new sections are *appended* to the existing sections:


            ![MRE](https://raw.githubusercontent.com/SetTrend/WpfFlowDocumentFlaw/refs/heads/main/.doc/Flow%20document%20controls%20Section%20error.gif)

## Desired Situation

When replacing Flow Document content in a Flow Document control using …
```xaml
new TextRange(TextBox.Document.ContentStart, TextBox.Document.ContentEnd).Load(ms, DataFormats.Xaml);
```

… *all* previous content should be replaced.

## Reproduction Steps

Please refer to this MRE for details:
https://github.com/SetTrend/WpfFlowDocumentFlaw

### Impact

**Can't use.**

### Configuration

- .NET 9.0
- Windows 10x64

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.