0

Is there any XAML element that will automatically wrap to a new line for sub elements that don't have enough room on a line?

What I mean is that on a wide screen I'll get:

Box1 Box2 Box3

And on a narrow one:

Box1 Box2

Box3

Without having to listen to events and fix it by code.

The comments mention VariableSizedWrapGrid as a solution. But I can't figure out how to make it wrap.

ispiro
  • 26,556
  • 38
  • 136
  • 291

2 Answers2

0

You can use a simple GridView to do it. If you don't set a Height, it should work like a charm.

<GridView Name="xConcerts" ItemsSource="{x:Bind Artist.UpcomingEvents, Mode=OneWay}">
    <GridView.ItemTemplate>
        <DataTemplate x:DataType="songkick:EventExt">
            <Border CornerRadius="8" Background="{ThemeResource ThemeGrayHighColorBrush}" Opacity="0.8">
                <StackPanel Margin="18,2">
                    <TextBlock Text="{x:Bind FullDisplayDate, Converter={StaticResource FormatStringToDateDayConverter}}" Style="{ThemeResource ThemeDateBoldStyle}"/>
                    <TextBlock Text="{x:Bind FullDisplayDate, Converter={StaticResource FormatStringToDateMonthConverter}}" Style="{ThemeResource ThemeDateBoldStyle}" Margin="0,-4,0,0"/>
                </StackPanel>
            </Border>
        </DataTemplate>
    </GridView.ItemTemplate>
    <GridView.ItemContainerTransitions>
        <TransitionCollection>
            <RepositionThemeTransition/>
        </TransitionCollection>
    </GridView.ItemContainerTransitions>
</GridView>
0

According to your requirement, using the WrapPanel control in WinRTXamlToolkit will meet your needs.
Sample code here:

<Page x:Class="TestDemo.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:Tool="using:WinRTXamlToolkit.Controls"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:local="using:TestDemo"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d">

<Tool:WrapPanel>
    <Button Width="200" Margin="10">1</Button>
    <Button Width="200" Margin="10">2</Button>
    <Button Width="200" Margin="10">3</Button>
</Tool:WrapPanel>
</Page>

And the output here:output

Jay Zuo
  • 15,653
  • 2
  • 25
  • 49
Jerry Li
  • 1,042
  • 9
  • 8