RichTextBox.Selection.GetPropertyValue(FontStyleProperty) returns DependencyProperty.UnsetValue for Hyperlink with Italic style
See original GitHub issue- .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
.
Here only a part of the hyperlink is selected, the button is blue.
The whole hyperlink is selected, the button is red (even though the whole text is Italic
).
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:
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top GitHub Comments
No, this happens as long as the starting position is included in the selection (i.e. even for the first character only). The reason is because the parent the property is read from is the Paragraph and the paragraph does not have italic set - basically the cursor is not inside a run, like this:
I’m not sure what feedback is expected from me, but I would prefer for this issue to be fixed at some point 🐝