Search code examples
wpflistboxwidthfixed

WPF ListBox fixed width


I have a ListBox in a PopupControl. Problem is that while scrolling, Popup resizes to fit the actual widest element.

How can I avoid this resizing and adjust automatically to the widest element in the whole list?

I tried to put it in a Grid but without success.


Solution

  • 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.