Skip to content

Learn Mobile Development

Alamgeer's Blog

Menu
  • Home
  • Privacy Policy
Menu
FlexLayout in MAUI

How to use FlexLayout in MAUI

Posted on December 2, 2022January 18, 2023 by Learn Mobile Development

FlexLayout in MAUI is a layout that can arrange its children horizontally and vertically in a stack. It is also wrap its children if there are too many children to fit in a single row or column. FlexLayout can control orientation and alignment, and adapt to different screen sizes.

In this article, I’m going to show you how to use FlexLayout in MAUI to add skills.

Let’s Start

1 – Setting up the UI

1.1 – MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:converter="clr-namespace:MAUIFlextLayout"
             x:Class="MAUIFlextLayout.MainPage">

     <ContentPage.Resources>
            <converter:StringToReverseBoolConverter x:Key="IsLableShow" />
            <converter:StringToViewSizeStringConverter x:Key="ViewSizeConverter" />
    </ContentPage.Resources>

    <ScrollView Padding="0,0,0,20">
        <VerticalStackLayout
            Spacing="15"
            Padding="20,20"
            VerticalOptions="Start">

            <Image
                Source="dotnet_bot.png"
                SemanticProperties.Description="Cute dot net bot waving hi to you!"
                HeightRequest="200"
                HorizontalOptions="Center" />

            <Label Text="Skills : "
                   FontSize="20"
                   Margin="5,0,0,0"
                   FontAttributes="Bold"/>

            <FlexLayout
                    x:Name="FlexSkillContainer"
                    Margin="5,-10,5,5"
                    AlignContent="Start"
                    AlignItems="Start"
                    HorizontalOptions="FillAndExpand"
                    VerticalOptions="Fill"
                    Direction="Row"
                    JustifyContent="Start"
                    BindableLayout.ItemsSource="{Binding Skills}"
                    Wrap="Wrap" >

                   <BindableLayout.ItemTemplate>
                        <DataTemplate>
                             <Frame
                                Margin="2"
                                Padding="4"
                                BackgroundColor="{StaticResource ColorFocused}"
                                CornerRadius="15">
                                   <StackLayout
                                        Margin="5,0,5,0"
                                        Orientation="Horizontal">

                                            <Label
                                                x:Name="LabelSkill"
                                                FontSize="18"
                                                Text="{Binding .}"
                                                Margin="5,0,5,0"
                                                TextColor="{StaticResource ColorWhite}"
                                                VerticalOptions="Center" />

                                            <Image
                                                x:Name="ImgCross"
                                                HeightRequest="24"
                                                HorizontalOptions="End"
                                                Source="cross.png"
                                                VerticalOptions="Center"
                                                WidthRequest="24">

                                                <Image.GestureRecognizers>
                                                    <TapGestureRecognizer Tapped="OnDeleteSkillClicked" />
                                                </Image.GestureRecognizers>

                                            </Image>

                                 </StackLayout>
                             </Frame>
                        </DataTemplate>
                   </BindableLayout.ItemTemplate>

             </FlexLayout>

            <FlexLayout Direction="Row" HeightRequest="50">

                <Entry
                    x:Name="SkillEntry"
                    Margin="5"
                    FlexLayout.Basis="{Binding Source={x:Reference SkillEntry}, Path=Text, Converter={StaticResource ViewSizeConverter}}"
                    FontSize="20"
                    HeightRequest="50"
                    VerticalOptions="Fill"
                    HorizontalOptions="FillAndExpand"
                    Keyboard="Text"
                    Placeholder="Add Skill" />

                <Image
                    x:Name="ImageCheck"
                    FlexLayout.Basis="10%"
                    HeightRequest="35"
                    FlexLayout.AlignSelf="Center"
                    VerticalOptions="CenterAndExpand"
                    IsVisible="{Binding Source={x:Reference SkillEntry}, Path=Text, Converter={StaticResource IsLableShow}}"
                    Source="check.png"
                    WidthRequest="35">

                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
                    </Image.GestureRecognizers>
                 </Image>

            </FlexLayout>

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>
  • As in the above MainPage.xaml I have used two FlexLayout first FlexLayout has used for showing the list of skills and second FlexLayout contains ‘Entry’ and ‘Image’.
  • I have used below properties in FlexLayout:
  1. Direction=”Row” => Children will appear horizontally.
  2. JustifyContent=”Start” => Children will aligned from start without any spacing.
  3. Wrap=”Wrap” => FlexLayout will wrap its children. If there are too many children to fit in a single row.
  • In the second FlexLayout i have used FlexLayout.Basis attached property to its children.
  • FlexLayout.Basis, defines the amount of space that’s allocated to a child on the main axis.
  • For Entry i have used StringToViewSizeStringConverter converter to manage the width size.

2 – Create a StringToViewSizeStringConverter.cs converter

using System;
using Microsoft.Maui.Layouts;
using System.Globalization;

namespace MAUIFlextLayout
{
    public class StringToViewSizeStringConverter : IValueConverter
    {
        public StringToViewSizeStringConverter()
        {
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string val = (string)value;

            if (!string.IsNullOrEmpty(val))
            {
                return new FlexBasis(0.90f, true);
            }
            else
            {
                return new FlexBasis(1f, true);
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return !((bool)value);
        }
    }
}

  • As in the above StringToViewSizeStringConverter.cs If Entry text length is more than 1 then StringToViewSizeStringConverter converter will return 90% of FlexBasis else 100% FlexBasis.
  • And I have used another StringToReverseBoolConverter converter to Image for hiding and showing.

3 – Create another StringToReverseBoolConverter.cs converter

using System;
using System.Globalization;

namespace MAUIFlextLayout
{
    public class StringToReverseBoolConverter : IValueConverter
    {
        public StringToReverseBoolConverter()
        {
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string val = (string)value;

            if (!string.IsNullOrEmpty(val))
            {
                if (val.Length > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return !((bool)value);
        }
    }
}
  • If Entry text length is more than 1 then image icon will be visible else not visible.

4 – Manage Add/Delete skills in MainPage.xaml.cs

using System.Collections.ObjectModel;
using System.ComponentModel;

namespace MAUIFlextLayout;

public partial class MainPage : ContentPage, INotifyPropertyChanged
{
    private ObservableCollection<string> _skills;
    public ObservableCollection<string> Skills
    {
        get
        {
            return _skills;
        }
        set
        {
            _skills = value;
            OnPropertyChanged("Skills");
        }
    }

	public MainPage()
	{
		InitializeComponent();
        Skills = new ObservableCollection<string>();
        BindingContext = this;
    }

    void OnAddSkillClicked(System.Object sender, System.EventArgs e)
    {
        Skills.Add(SkillEntry.Text);
        SkillEntry.Text = "";
    }

    void OnDeleteSkillClicked(System.Object sender, System.EventArgs e)
    {
        string skill = (sender as Image).BindingContext as string;

        if(!string.IsNullOrEmpty(skill))
        {
            Skills.Remove(skill);
        }
    }
}

Now, We have completed the coding, Let’s try to run the application.

5 – Result

That’s all for now!

You can check the full source code here.

Happy Coding! 😀

You may also like

UniformItemsLayout in MAUI

How to use UniformItemsLayout in MAUI

Expander in MAUI

How to use Expander in MAUI

Post Views: 394
Share article with

1 thought on “How to use FlexLayout in MAUI”

  1. dofollow backlinks means says:
    October 29, 2025 at 9:56 AM

    Perfect piece of work you have done, this site is really cool with superb info .

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I'm Alamgeer Ashraf and having 11+ years of experience in enterprises mobile application development with Xamarin Native, Xamarin Forms & .Net MAUI.

Archives

  • February 2023 (1)
  • January 2023 (9)
  • December 2022 (5)
  • November 2022 (6)

Latest Posts

  • Prevent Dark Mode in Xamarin forms
    How to Prevent Dark Mode in Xamarin formsFebruary 3, 2023
  • apply color to Images
    How to apply color to Images and Icons in MAUIJanuary 30, 2023
  • iOS Large Page Title
    How to set iOS large page title in MAUIJanuary 26, 2023
  • Change StatusBar Color
    How to change StatusBar color in MAUIJanuary 22, 2023
  • Item reordering to CollectionView
    How to apply item reordering to CollectionView GridItemsLayout in MAUIJanuary 18, 2023

Popular Posts

  • How to apply color to Images and Icons in MAUI
  • How to use CollectionView as a GridItemLayout in Xamarin Forms
  • How to change StatusBar color in MAUI

Latest Comments

  1. knight online makro on Implementation Of Biometric Authentication in Xamarin FormsFebruary 12, 2026

    Your blog is always a highlight of my day

  2. dịch vụ backlink top.com vn on How to use CollectionView as a GridItemLayout in Xamarin FormsNovember 20, 2025

    Great post, you have pointed out some fantastic details , I besides think this s a very superb website.

  3. ryzen sunucu kirala on Implementation Of Biometric Authentication in Xamarin FormsNovember 4, 2025

    Thank you for sharing your personal experience and wisdom with us Your words are so encouraging and uplifting

  4. dofollow backlinks means on How to use FlexLayout in MAUIOctober 29, 2025

    Perfect piece of work you have done, this site is really cool with superb info .

  5. backlinks que es on How to use ObservableObject in MAUI for Data BindingOctober 28, 2025

    I like this internet site because so much useful stuff on here : D.

Our Visitor

0 0 8 9 3 3
Users Today : 3
Users Yesterday : 3
Users Last 7 days : 23
Users Last 30 days : 97
Users This Month : 3
Total views : 15359
How to set iOS large page title in MAUI
Trending
How to set iOS large page title in MAUI

Category

  • .Net MAUI
  • MAUI Community Toolkit
  • MVVM
  • Xamarin Community Toolkit
  • Xamarin Forms

Contact Me

  • LinkedIn
      © 2026 Learn Mobile Development