Reputation: 11827
I have a ListView and TextBox for entering search text.
When the user searches for some text, I start a long-running search operation (on the UI thread, through a UI-thread-timer), and every now and again, while the search is still active, I change the ICollectionView.Filter
property, to cause the ListView to refresh and present more items that the search has found as matching.
The problem is that if the user right clicks on one of the items, and then as Search is happening in the background, the tree is refreshed, then the ContextMenu disappears.
How can I prevent that from happening?
Upvotes: 0
Views: 355
Reputation: 5367
Here's my theory: Because the whole tree is refreshed, WPF cannot know that the item (which was right-clicked) is the exact same item as after the refresh. Technically, that Item isn't even "there" anymore. It's really a new item with the exact same properties (from the ListView's perspective).
There are a some ways you can try to remediate this:
Capture the right-click of the item, store the item; capture the tree refresh, check if the item is equal to the stored item; if equal show the ContextMenu.
Instead of refreshing the whole tree, add items to the end of the list.
While ContextMenu is open, suspend refreshing the tree.
Upvotes: 1