How do we use the WrapLayout Control with dynamic items?

1 Answer 125 Views
WrapLayout
Mark
Top achievements
Rank 3
Iron
Iron
Iron
Mark asked on 15 Dec 2023, 05:33 PM | edited on 15 Dec 2023, 05:55 PM

I have tried this sort of thing to create a button that wrap within an area (and scroll if they don't fit)


<ScrollView x:Name="scrollView" Grid.Row="1" Grid.Column="0" VerticalOptions="Fill" HorizontalOptions="Fill">
    <telerik:RadWrapLayout Orientation="Horizontal" BackgroundColor="#404040" VerticalOptions="Fill" HorizontalOptions="Fill">
        <telerik:RadItemsControl x:Name="HashTagList" ItemsSource="{Binding HashTags, Mode=TwoWay}" VerticalOptions="Fill" HorizontalOptions="Fill">
            <telerik:RadItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Text="{Binding HashTag}" Style="{StaticResource hashTagButtonStyle }" CommandParameter="{Binding HashTag}"></Button>
                </DataTemplate>
            </telerik:RadItemsControl.ItemTemplate>
        </telerik:RadItemsControl>
    </telerik:RadWrapLayout>
</ScrollView>


The buttons are only rendered in a stack, how do we render out buttons that will work like the doc example, except the buttons are added dynamically

Ideally the WrapLayout has an ItemSource and DataTemplate like an Items Control?

Am I missing something?

Some things I have tried

This gives me an exception : Layout cycle detected.  Layout could not complete.


<ScrollView x:Name="scrollView" Grid.Row="1" Grid.Column="0" VerticalOptions="Fill" HorizontalOptions="Fill">
    <telerik:RadWrapLayout Orientation="Horizontal" BackgroundColor="#404040" VerticalOptions="Fill" HorizontalOptions="Fill">
        <FlexLayout Wrap="Wrap" BindableLayout.ItemsSource="{Binding HashTags, Mode=TwoWay}" VerticalOptions="Fill" HorizontalOptions="Fill" FlowDirection="LeftToRight">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <Button Text="{Binding HashTag}" Style="{StaticResource hashTagButtonStyle }" CommandParameter="{Binding HashTag}" FlowDirection="LeftToRight"></Button>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </FlexLayout>
    </telerik:RadWrapLayout>
</ScrollView>

 

This works (ie not using the WrapLayout)


<ScrollView x:Name="scrollView" Grid.Row="1" Grid.Column="0" VerticalOptions="Fill" HorizontalOptions="Fill" Padding="4, 4, 4, 4" BackgroundColor="#404040">
    <!--<telerik:RadWrapLayout Orientation="Horizontal" BackgroundColor="#404040" VerticalOptions="Fill" HorizontalOptions="Fill">-->
        <FlexLayout Wrap="Wrap" BindableLayout.ItemsSource="{Binding HashTags, Mode=TwoWay}" VerticalOptions="Fill" HorizontalOptions="Fill" FlowDirection="LeftToRight">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <Button Text="{Binding HashTag}" Style="{StaticResource hashTagButtonStyle }" CommandParameter="{Binding HashTag}" FlowDirection="LeftToRight"></Button>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </FlexLayout>
    <!--</telerik:RadWrapLayout>-->
</ScrollView>

Is this control for static content only?

1 Answer, 1 is accepted

Sort by
1
Martin Ivanov
Telerik team
answered on 20 Dec 2023, 09:05 AM

Hello Mark,

To achieve your requirement, you can use the BindableLayout attached properties directly on the WrapLayout like so:

<telerik:RadWrapLayout BindableLayout.ItemsSource="{Binding HashTags, Mode=TwoWay}">	
	<BindableLayout.ItemTemplate>
		<DataTemplate>
			<Button Text="{Binding HashTag}" Style="{StaticResource hashTagButtonStyle }" CommandParameter="{Binding HashTag}" FlowDirection="LeftToRight"></Button>
		</DataTemplate>
	</BindableLayout.ItemTemplate>
</telerik:RadWrapLayout>

I also attached a sample project showing this. Can you give it a try and let me know if it helps?

Regards,
Martin Ivanov
Progress Telerik

A brand new .NET MAUI course was just added to the Virtual Classroom. The training course is developed to help you get started with the Telerik UI for .NET MAUI components and features. It aims to put you in the shoes of an engineer who adds new features to an existing application. You can check it out at https://learn.telerik.com
Mark
Top achievements
Rank 3
Iron
Iron
Iron
commented on 20 Dec 2023, 07:39 PM

Hi, Thanks, I will have a look.
Tags
WrapLayout
Asked by
Mark
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or