dotnet / dotnet/wpf

RichTextBox.Selection.GetPropertyValue(FontStyleProperty) returns DependencyProperty.UnsetValue for Hyperlink with Italic style

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

Description

* .NET Core Version: .NET 6.0.9
* Windows version: Windows 10 21H2 (19044.2006)
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

**Problem description:**

We use `RichTextBox.Selection.GetPropertyValue(FontStyleProperty)` to determine the selected text's style. The issue is, if the selected text is `Hyperlink` and it's fully selected, the returned style is incorrect if it's not default.

As an example for the repro below, the button's color depends on whether the selected text is `Italic` or not (blue if yes, otherwise red). By pressing the button the selected text's style is changed to/from `Italic`.

Here nothing is selected, the whole hyperlink's text is `Italic`.

![image](https://user-images.githubusercontent.com/14861420/194855110-99a1da9a-be61-4426-b8a0-b842d5eff241.png)

Here only a part of the hyperlink is selected, the button is blue.

![image](https://user-images.githubusercontent.com/14861420/194855243-7fcf2529-0459-498b-a743-d221f27f1096.png)

The whole hyperlink is selected, the button is red (even though the whole text is `Italic`).

![image](https://user-images.githubusercontent.com/14861420/194855389-1ad254f0-aeb9-4d5d-ab97-6bc54e509a49.png)

This happens because when the whole text is selected `GetPropertyValue(FontStyleProperty)` returns `DependencyProperty.UnsetValue`.

**Actual behavior:**

`GetPropertyValue(FontStyleProperty)` returns `DependencyProperty.UnsetValue` for `Hyperlink` if has `Italic` font style.

**Expected behavior:**

`GetPropertyValue(FontStyleProperty)` should return `FontStyles.Italic` for `Hyperlink` if has `Italic` font style.

**Minimal repro:**

https://github.com/vonzshik/WpfRichTextBoxItalicLink

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.