WrapPanel not wrapping when in a StackPanel with Horizontal orientation

前端 未结 2 1611
心在旅途
心在旅途 2021-02-19 07:20

The labels in the example below (WPF/XAML) just parade off the screen, no wrapping occurs. Removing the orientation works, but doesn\'t provided the needed functionality/look &

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 07:48

    What you're doing isn't possible because of the algorithm that StackPanel uses when doing horizontal layout. It's basically going to ask each child element how big it wants to be and however much space it asks for it's going to give it.

    You would either need to:

    1. Set a Width or MaxWidth on the WrapPanel.
    2. Use a WrapPanel as the outer panel in place of the StackPanel.

提交回复
热议问题