Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I decided to use a <code>Control</code> that supports HTML so that I could use an <code>IValueConverter</code> to update the value of the displayed text on the fly without affecting any active bindings. I used the code from <a href="http://blogs.u2u.be/diederik/post/2010/08/31/a-rich-html-textblock-for-wpf.aspx" rel="nofollow noreferrer">here</a> and modified it so that it looked like a <code>TextBlock</code> within my <code>ListView</code>:</p> <pre class="lang-cs prettyprint-override"><code>BorderBrush = Brushes.Transparent; SelectionBrush = Brushes.Transparent; Cursor = Cursors.Arrow; BorderThickness = new Thickness(0); Background = Brushes.Transparent; </code></pre> <p>However, I still needed to trigger the <code>IValueConverter</code> so that the display is updated as the user types in their search query (code from <a href="https://stackoverflow.com/a/4489086/1244630">here</a>):</p> <pre class="lang-cs prettyprint-override"><code>ICollectionView view = CollectionViewSource.GetDefaultView(ItemsSource); view.Refresh(); </code></pre> <p>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 <code>IValueConvertor</code> simply inserted the bold tags to match the search query:</p> <pre class="lang-xml prettyprint-override"><code>&lt;RichTextBox Text="{Binding Path=DisplayItem, Converter={StaticResource searchFormatter}, ConverterParameter={x:Reference txtSearch}}"/&gt; </code></pre> <p>Where <code>searchFormatter</code> this time is an <code>IValueConvertor</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload