dotnet / dotnet/wpf

Using different TextFormattingModes with FlowDocument can sometimes use the incorrect mode.

Open
#1,101 0 comments 1 reaction 0 assignees View on GitHub
.NET Framework Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: any
* Windows version: Windows 10 1903
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes



**Problem description:**

Using `TextOptions.SetTextFormattingMode()` on a `FlowDocument` or `RichTextBox` should use the specified mode when using different modes in the same application.

**Actual behavior:**

The actual mode used is somewhat random, and you cannot change it after it is set.

**Expected behavior:**

The mode specified should be used.

**Minimal repro:**

Create/use many FlowDocument (or RichTextBox) objects with different formatting modes. E.g.

```
var richText1 = new RichTextBox();
TextOptions.SetTextFormattingMode(richText1, TextFormattingMode.Ideal);
var richText2 = new RichTextBox();
TextOptions.SetTextFormattingMode(richText2, TextFormattingMode.Display);
```

I have tracked this down to a bug in [`PtsCache.AcquireContextCore`](https://github.com/dotnet/wpf/blob/8c7ab1592b6c70e732106aeabf58f215d4b71c22/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs#L181), where it does not take the desired textFormattingMode into account when looking up an existing context to use from the cache.

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.