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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:29:38+00:00 2026-05-18T05:29:38+00:00

I am trying to bind a few WPF controls to a trie. I have

  • 0

I am trying to bind a few WPF controls to a trie. I have created a wrapper that exposes the methods in the trie as properties. I am trying to filter my listbox with the matches returned by the trie. When there are too many matches I don’t want to enumerate all the matches since that takes a few seconds, and is totally unnecessary. I have solved this declaratively by using an MultiBinding that takes both the lazy-loading Matches and then NumMatches which is much faster to calculate. The MultiBindingConverter first evaluates the NumMatches sent into the function. If this is smaller than a certain value, only then does it attempt to evaluate the Matches property.

The problem is that when Matches changes, so does NumMatches. My converter is thus called two times, once when Matches changes and one when NumMatches changes. This would have been fine, even though perhaps a bit bug-prone, if WPF didn’t (apparently) cache data, because even though both properties have changed at the time, the fresh value isn’t fetched but a cached one used. The converter will be called with mismatching arguments, count will be for example 100 (safe to enumerate) but the enumeration will cause a million or two values to be accessed, since the fresh Matches list is not fetched until the PropertyChanged for Matches is called (they are updated in the same wrapper property, remember) How should I solve this? I want to solve it declaratively.

My ideas are following:

1) Find a better way to solve the paging, not using MultiBinding

2) Disable caching

Which one of these are the most plausible? How much have I violated WPF plumbing here?

This is some of my XAML:

        <ListBox SelectionChanged="ListBox_SelectionChanged"  Height="250">
        <ListBox.ItemsSource>
            <MultiBinding>
                <MultiBinding.Converter>
                    <mine:PagingMultiValue> </mine:PagingMultiValue>
                </MultiBinding.Converter>
                <Binding Path="Matches"></Binding>
                <Binding Path="NumMatches"></Binding>
            </MultiBinding>
        </ListBox.ItemsSource>
    </ListBox>

UPDATE

Here is some of my TrieWrapper:

public string Text
        {
            get { return text; }
            set
            {
                if (string.Equals(text, value))
                    return;
                text = value;
                OnMatchesChanged();
                OnNumMatchesChanged();
                OnTextChanged();

            }
        }

Even though I have control over the source for my Trie datastructure, I would prefer not altering it by exposing the current matches through a property. This is why I have this “hack” instead. When OnMatchesChanged() is called, it is updated with the old value for NumMatches. Then directly afterwards it is updated with the correct value for both. If I change the order of the updates the only thing that changes is when exactly the wrong enumeration occurs, either when I add to the Text search string or remove from it.

Thanks!

  • 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-05-18T05:29:39+00:00Added an answer on May 18, 2026 at 5:29 am

    Unless you have some good reason to do this another way, you should use the fact that ListBox has built in UI Virtualization and follow something along the lines of the following article in order to build the data virtualization.

    http://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/10/01/ui-virtualization-vs-data-virtualization-part-2.aspx

    (UI Virtualization link from MSDN)

    http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.aspx

    Your current solution is a data virtualization solution (being lazy evaluated) but it is not done in an way in which WPF can easily interface with it. By using a custom ICollectionView implementation (the article derives ListCollectionView for convenience) you don’t have to do anything to the ListBox except set the ItemsSource to be a CollectionViewSource object bound to your dataset. This keeps the XAML completely readable (compared to using multi bindings etc) and improves performance since it wont be using your converter to work out what elements are required to be rendered, WPF will use it’s own methods to determine what should be on screen or not.

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

Sidebar

Related Questions

I'm trying to bind controls in a WPF form to an interface and I
I'm trying to bind a list of custom objects to a WPF Image like
This is the exception that I'm getting when I'm trying to bind to a
I have a custom class Contact . I am trying to bind a List<Contact>
I'm trying to bind Fancy box links so that when the new links are
just trying to tie up a few loose odds and ends here. I have
Im trying to bind a list of images to a Listbox, but all I
I'm trying to bind an image's source to a string in a listbox with
I'm trying to bind the following shortcut: Ctrl + W to close tabs How
I am trying to bind an event to a method of a particular instance

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.