How can I achieve this mix of StackPanel and UniformGrid behavior?

后端 未结 1 1968
一生所求
一生所求 2020-12-18 05:43

I want to put elements inside a control so that they initially fit like this (like a StackPanel with Horizontal orientation):

相关标签:
1条回答
  • 2020-12-18 06:06

    Easiest/Quickest route, throw it in a ViewBox with it set to Stretch="Uniform" to do it for you, as an example like below, just add/subtract rectangles and you'll get the concept...

    <Viewbox Stretch="Uniform" MaxHeight="60" MaxWidth="200">
        <StackPanel Orientation="Horizontal">
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
             <Rectangle Fill="Red" Margin="5" Height="50" Width="50"/>
         </StackPanel>
    </Viewbox>
    

    Hope this helps. Cheers

    0 讨论(0)
提交回复
热议问题