Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF Custom ItemsControl notifies underneath Containers

$
0
0

I am trying to write a small simple custom ListBox. I started deriving fromItemsControl and I managed to build almost everything the normal microsoftListBox includes except SelectedItems functionality.

The problem is how to notify my Containers that user has changed SelectedItems list from his ViewModel. Or better said how to tell my displayedContainers to set their IsSelected to true once their DataContext is included in theSelectedItems list.

I am offering the SelectedItems property in my custom ListBox and I am listening to propertychanged callback so once user sets few data items to be selected through data binding mySelectedItems gets them all.

It's not a 101 problem and to post code of this custom ListBox would turn this question kinda into a blog post about how to write a custom ListBox since you guys would need every piece of code to understand whats going on under the hood and I would need to post everything.

Therefore I am hoping to get some suggestions or just ideas instead of coded solution.

I was thinking to tell my owner which is the custom Listbox to Invalidate Measure once I get something from the SelectedItems propertychanged callback since then I know that I have to tell my containers to figure out which of them is selected or not. The Invalidate Measure on owner would cause to re-measure underneath containers and inside theirmeasureoverride method i could handle selection. But this seems a performance killer since I would need to handle selection and do measuring logic insidemeasureoverride method of each container.

I think this approach would be an epic fail but maybe you guys know a better one.

Sorry for this looong novel I hope you get me and what I my problem is.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>