Reputation: 3369
I've seen this scenario a hundred times:
The developer needs to display some items. No functionality (scrolling, selection etc.) is required, really just display a bunch of stuff. The solution? They use a ListBox
, then write loads of XAML to remove all of its appearance and behaviour (often forgetting something, leading to strange bugs).
My question is: Why not use an ItemsControl
, which does exactly that, take items from a list and put them on the window (put, by default, into a StackPanel
, although that can be changed)? Are there any concerns that I don't know about? Is there a reason why using an ItemsControl
directly like this is not a good idea, or is this just a matter of people not knowing they can do that?
Upvotes: 0
Views: 52
Reputation: 3451
My guess is that listbox features more regularly in tutorials as is easier to find in visual studio and blend.
You are completely correct to look to itemscontrol. The list box extends this control to support selection of items, unless you need to be able to select something, just use the itemscontrol. This should be the same principle adopted throughout, always use the lower level control to meet your requirement.
Incidentally, I've never encountered issues with itemscontrol.
Upvotes: 2