Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:24:48+00:00 2026-06-08T14:24:48+00:00

I’m currently working on a highlightable richtextbox control in WPF. The user can type

  • 0

I’m currently working on a highlightable richtextbox control in WPF. The user can type some text into a search box and the richtextbox is highlighting the occurences of the searched word.
Everything works fine until I have hyperlinks in the richtextbox, for example:

blablabla stackoverflow.com

And I search for the term:

st

It highlights the text (“st” in stackoverflow) correctly with a red foreground.
But when I’m pressing a backspace – so the search term becomes the single “s” letter -, I get an exception:

System.ArgumentException: 'NamedObject' parameter type is not valid for formatting property 'Foreground'.
Parameter name: value

This is because my algorithm is looks like this:

  1. Highlight the text in the richtextbox: I add every highlighted TextRange to a Dictionary, where the key is the highlighted TextRange, and the value is the old foreground property of that TextRange which I retrieve with this code:

    textrange.GetPropertyValue(TextElement.ForegroundProperty)
    
  2. Every time a user changes the filter string, I delete the old highlighting and I “re-highlight” the richtextbox with the new filter string like in Step 1.

    • The exception comes from the “delete the highlighting” part of the process. To delete the highlighting, I enumerate the Dictionary, and for every TextRange I reset the ForegroundProperty to the saved value:

      foreach (var textRangeEntry in highlightedTexts)
      {                
          textRangeEntry.Key.ApplyPropertyValue(TextElement.ForegroundProperty, textRangeEntry.Value);
      }
      

The problem is that sometimes the saved ForegroundProperty becomes a DependencyProperty.UnsetValue – and I get an exception.

Which is strange. It looks like the ForegroundProperty “doesn’t like” the UnsetValue, but for example, when I filter to

ov

in the text

blablabla stackoverflow.com

and then when I’m erasing the “v”, everything’s OK.

The exception only comes out when I’m highlighting the beginning of hyperlinks.

Is it a strange bug in WPF or I do something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:24:49+00:00Added an answer on June 8, 2026 at 2:24 pm

    I have realized that this problem (bug?) is inside the textrange.GetPropertyValue call. I will repost this question in a shorter and a more specific form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.