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 can I arrow up/down past a ListBox item with Visibility Collapsed?

0
Posted

Why can I arrow up/down past a ListBox item with Visibility Collapsed?

0

Because ListBox doesn’t expect there to be “invisible” ListBoxItems. If you try the obvious workaround of leaving the ListBoxItem Visible and marking its Content Collapsed, arrow navigation no longer gets “stuck” – but the scenario is still confusing to the user because the ListBox lets focus get set to the “invisible” item. Rather than playing with Visibility, consider the more direct approach of removing items from the collection if you don’t want them to be visible. An elegant approach is to use an ObservableCollection for storing items and then assign that collection to the ItemsSource property of the ListBox. Because ObservableCollection implements INotifyCollectionChanged, changes to it (e.g., via Add/Remove) are automatically communicated to ListBox’s ItemsControl base class which automatically updates the ListBox display. All you need to do is keep the collection up to date – everything else is handled for you.

Related Questions

What is your question?

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

Experts123