I have a ListBox in a PopupControl. Problem is that while scrolling, Popup resizes to fit the actual widest element. How to avoid this resizing and adjust automatically to the widest element in the whole list? I tried to put it in a Grid but without succes.
ok this is the solution: Adding this property
<ListBox VirtualizingStackPanel.IsVirtualizing="False"
The resizing stops because now the Panel contains all elements and the width is adjusted respecting the widest one. With Virtualizing Panel, it's only a part of items displayed and the ListBox adjusts the widht to the actual visible widest element.
Disadvantade is, that we do not use Virtualizing Panel anymore (which is default on)
Most WPF UIElement
controls have a Width
property which can be set to "Auto
" so they will take up as much space as their widest element.
If you want to keep virtualizing on, you can set the Popup.Width
to a constant.
Of course, to pick the right constant, you'll have to calculate (or at least guess) how wide each ListBoxItem
will be, and pick the max. ... Usually it's not too hard to get a rough guess, based on your content.