Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why is selection behavior incorrect when I have the same object in a ListBox multiple times?

0
Posted

Why is selection behavior incorrect when I have the same object in a ListBox multiple times?

0

For compatibility with WPF, of course! 🙂 Due to the way ItemsControl is implemented, it is necessary for it to maintain a mapping from the objects it contains to the corresponding wrappers (i.e., ListBoxItems) that get created for them. This is handled by the ItemContainerGenerator.ContainerFromItem method on WPF and by ListBox.GetListBoxItemForObject on Silverlight – but the idea is the same. When the same object reference is added to the ListBox multiple times, this mapping breaks down because it isn’t prepared for a single object to map to multiple containers. As it happens, the WPF and Silverlight behaviors differ slightly here. Both seem wrong, but I’ll suggest that the Silverlight behavior is slightly less wrong.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.