I am using a Popup in the control template of a MenuItem.
However, I don't know in advance how many items will be in the menu item. As a result, the popup might not fit on the screen and some items might not be accessible.
My solution is to set MaxSize to, say, 500, and wrap the ItemsPresenter in a ScrollViewer.
However, this does not take into account the size of the screen.
Is there a way to specify that the popup should be as large as it needs to be without going outside the screen boundaries?
Apparently, WPF is smart enough to set the direction of the popup (up /down, right/ left) so that it tends to be centered. For example, if the popup is at the bottom of the screen, it will popup above the popup position, not below it. But I don't see anything regarding the max size.