dotnet / dotnet/wpf

The TextBox's SelectionTextBrush property doesn't work

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

Description

* .NET Core Version: Microsoft.NETCore.App 6.0.0-preview.3.21201.4 / .NET SDKs 6.0.100-preview.3.21202.5
* Windows version: 2004
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes



**Problem description:**
Hi, the [SelectionTextBrush](https://docs.microsoft.com/dotnet/api/system.windows.controls.primitives.textboxbase.selectiontextbrush) property of TextBox doesn't work. I've set it to `Red` but nothing happens.

P.S.: I've faced this behavior the research an issue of our VisualStudio wizard - the foreground of the selected text is wrong. It's reproduced only for VS2019. So it's confused me - the property doesn't work in a common case but affects foreground in VS. In addition, our wizard use .Net 4.7.2. Can't understand how it works.
![image](https://user-images.githubusercontent.com/47348109/119493132-8cb73f00-bd68-11eb-8ab6-a005a280b44d.png)

Upd.: I've turned on the high-contrast mode and the color of the selected text in VS wizard changed to `Black` because by default the SelectionTextBrush uses the system's HighlightTextColor. It looks like the VS team use some hack or know something about how to force working this property :)

```csharp
//ReferenceSource
private static Brush GetDefaultSelectionTextBrush()
{
Brush selectionTextBrush = new SolidColorBrush(SystemColors.HighlightTextColor);
selectionTextBrush.Freeze();
return selectionTextBrush;
}
```

![image](https://user-images.githubusercontent.com/47348109/119495551-313a8080-bd6b-11eb-8cd9-381288b31dfc.png)


**Actual behavior:**
The selected text still black.

![image](https://user-images.githubusercontent.com/47348109/119491990-41506100-bd67-11eb-904d-a566325f538e.png)

**Expected behavior:**
The selected text should be red.

**Minimal repro:**
```xaml



```

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.