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 8906669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:42:58+00:00 2026-06-15T02:42:58+00:00

Consider the following scenario: I have a ListView that is bound to an ObservableCollection

  • 0

Consider the following scenario:

  • I have a ListView that is bound to an ObservableCollection using the DataContext:

    <ListView ItemsSource="{Binding}">
    

    The class containing the string data uses the DependencyProperty mechanism to keep the displayed content synced with the data collection.

  • The ListView has one column that is editable (I followed the tutorial here to achieve this); the ListViewItem is then either a TextBlock or a TextBox. This is done using a DataTemplate and two Style resources.
  • I’d like to format the string displayed in the TextBlock based on a search string. Specifically, I’d like to format the items of the ListView to become bold as the user types in their search query if there is a match (only the characters that match in sequence should be made bold). This only needs to be displayed for the text currently being rendered using the TextBlock (that is, text not currently being edited).

I’ve considered using an IMultiValueConverter that takes in a reference to the TextBlock that renders the data so that I can format the text appropriately. However, this will destroy the binding that I’ve set up:

<TextBlock.Text>
  <MultiBinding Converter="{StaticResource searchFormatter}" ConverterParameter="{x:Reference Name=txtSearch}">
    <MultiBinding.Bindings>
      <Binding Path="NameOfBoundDependencyProperty"/>
      <Binding RelativeSource="{RelativeSource Self}"/>
    </MultiBinding.Bindings>
  </MultiBinding>
</TextBlock.Text>

searchFormatter being the IMultiValueConverter and txtSearch being the TextBox containing the search query.

I’m still learning WPF so I’m not familiar with the best approach or to what’s possible. Is there a way to keep the data bound (so that edits reflect in the collection and the ListView) and still represent the data differently to the user (so that search matches may be bold)? Perhaps it would be cleaner if I manage the binding manually?

  • 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-15T02:42:59+00:00Added an answer on June 15, 2026 at 2:42 am

    I decided to use a Control that supports HTML so that I could use an IValueConverter to update the value of the displayed text on the fly without affecting any active bindings. I used the code from here and modified it so that it looked like a TextBlock within my ListView:

    BorderBrush = Brushes.Transparent;
    SelectionBrush = Brushes.Transparent;
    Cursor = Cursors.Arrow;
    BorderThickness = new Thickness(0);
    Background = Brushes.Transparent;
    

    However, I still needed to trigger the IValueConverter so that the display is updated as the user types in their search query (code from here):

    ICollectionView view = CollectionViewSource.GetDefaultView(ItemsSource);
    view.Refresh();
    

    I didn’t want to slow down the search process so I only forced this refresh if there was actually a match (or if the state of having a match moves to no match). My IValueConvertor simply inserted the bold tags to match the search query:

    <RichTextBox Text="{Binding Path=DisplayItem, Converter={StaticResource searchFormatter}, ConverterParameter={x:Reference txtSearch}}"/>
    

    Where searchFormatter this time is an IValueConvertor.

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

Sidebar

Related Questions

Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following scenario We have a simple database that involves two entities: user
Consider the following scenario: I have a page that can open a dialog (jquery
Please consider the following scenario. I have a form with a property: class MyForm
consider following scenario input string = WIPR.NS i have to replace this with WIPR2.NS
please consider the following scenario for .net 2.0: I have an event that is
Please consider the following scenario. I have a Task, that returns an object, lets
Consider the following scenario . I have an array of numbers: [ 1,2,3,4 ]
From couple of days i am thinking of a following scenario Consider I have
I have a question regarding a race condition scenario. The question: Consider the following

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.