{"id":518,"date":"2022-12-21T15:03:44","date_gmt":"2022-12-21T15:03:44","guid":{"rendered":"https:\/\/learnmobiledevelopment.com\/?p=518"},"modified":"2023-01-18T16:31:22","modified_gmt":"2023-01-18T16:31:22","slug":"uniformitemslayout-in-maui","status":"publish","type":"post","link":"https:\/\/learnmobiledevelopment.com\/index.php\/2022\/12\/21\/uniformitemslayout-in-maui\/","title":{"rendered":"How to use UniformItemsLayout in MAUI"},"content":{"rendered":"\n<p><strong><strong>UniformItemsLayout&nbsp;<\/strong>in<strong>&nbsp;MAUI<\/strong><\/strong>&nbsp;<strong>Community Toolkit<\/strong> is a layout where all <strong>rows<\/strong> and <strong>columns<\/strong> will have the same size. <strong><strong>UniformItemsLayout<\/strong><\/strong> is similar to <strong>Grid<\/strong>. For positioning the child in a particular cell we no need to specify row and column index in <strong>UniformItemsLayout<\/strong> like in <strong>Grid<\/strong>, It will automatically positioned child in row and column.<\/p>\n\n\n\n<p>In this article, I\u2019m going to show you how to use&nbsp;<strong><strong>UniformItemsLayout&nbsp;<\/strong>in<strong>&nbsp;MAUI<\/strong><\/strong>&nbsp;<strong>Community Toolkit<\/strong>.<\/p>\n\n\n\n<p><strong><strong>UniformItemsLayout&nbsp;<\/strong>in<strong>&nbsp;MAUI<\/strong><\/strong>&nbsp;<strong>Community Toolkit<\/strong> allow us to limit the <strong>maximum<\/strong> number of <strong>columns<\/strong> and <strong>rows<\/strong> using <strong>MaxRows<\/strong> and <strong>MaxColumns<\/strong> properties.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>MaxRows<\/strong> &#8211; Used for Getting\/Setting the maximum number of items in a row.<br><strong>MaxColumns<\/strong> &#8211; Used for Getting\/Setting the maximum number of items in a column.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p style=\"font-size:25px\"><strong>Let\u2019s Start<\/strong><\/p>\n\n\n\n<p>In this sample demo we will use&nbsp;<strong><a href=\"https:\/\/www.nuget.org\/packages\/CommunityToolkit.Maui\/\" target=\"_blank\" rel=\"noreferrer noopener\">CommunityToolkit.Maui<\/a><\/strong>&nbsp;nuget package.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>CommunityToolkit.Maui<\/strong><\/p>\n\n\n\n<p>CommunityToolkit.Maui&nbsp;is a collection of Converters, Behaviours, Animations, Custom Views, Effects, Helpers etc. It simplifies the developers task when building Android, iOS, macOS and WinUI applications using MAUI.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>1 \u2013 Install CommunityToolkit.Maui&nbsp;nuget package<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"606\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-1024x606.png\" alt=\"Expander in MAUI\" class=\"wp-image-422\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-1024x606.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-300x178.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-768x455.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-1536x909.png 1536w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529-850x503.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/ExpanderinMAUI-e1670421322529.png 1802w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>2 &#8211; In order to use the .NET MAUI Community Toolkit you need to call the extension method in your MauiProgram.cs&nbsp;file as follows:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using CommunityToolkit.Maui;\nusing Microsoft.Extensions.Logging;\n\nnamespace MAUIUniformItemsLayoutSample;\n\npublic static class MauiProgram\n{\n    public static MauiApp CreateMauiApp()\n    {\n        var builder = MauiApp.CreateBuilder();\n        builder\n            .UseMauiApp&lt;App>()\n            .UseMauiCommunityToolkit()\n            .ConfigureFonts(fonts =>\n            {\n                fonts.AddFont(\"OpenSans-Regular.ttf\", \"OpenSansRegular\");\n                fonts.AddFont(\"OpenSans-Semibold.ttf\", \"OpenSansSemibold\");\n            });\n\n#if DEBUG\n        builder.Logging.AddDebug();\n#endif\n\n        return builder.Build();\n    }\n}<\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3 \u2013 Setting up the UI<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3.1 \u2013 Create a MainPage.xaml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"utf-8\" ?>\n&lt;ContentPage\n    x:Class=\"MAUIUniformItemsLayoutSample.MainPage\"\n    xmlns=\"http:\/\/schemas.microsoft.com\/dotnet\/2021\/maui\"\n    xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml\"\n    xmlns:toolkit=\"http:\/\/schemas.microsoft.com\/dotnet\/2022\/maui\/toolkit\">\n\n    &lt;ContentPage.Resources>\n        &lt;ResourceDictionary>\n            &lt;Style TargetType=\"Button\">\n                &lt;Setter Property=\"CornerRadius\" Value=\"0\" \/>\n                &lt;Setter Property=\"TextColor\" Value=\"Black\" \/>\n            &lt;\/Style>\n            &lt;Style TargetType=\"Label\">\n                &lt;Setter Property=\"TextColor\" Value=\"Black\" \/>\n                &lt;Setter Property=\"FontAttributes\" Value=\"Bold\" \/>\n                &lt;Setter Property=\"Margin\" Value=\"0,10,0,0\" \/>\n            &lt;\/Style>\n        &lt;\/ResourceDictionary>\n    &lt;\/ContentPage.Resources>\n\n    &lt;ScrollView>\n        &lt;VerticalStackLayout Padding=\"10\" Spacing=\"15\">\n\n            &lt;Label Text=\"UniformItemsLayout with default settings\" \/>\n            &lt;toolkit:UniformItemsLayout x:Name=\"UniformItemsLayout_Default\">\n                &lt;Button BackgroundColor=\"#F5F5DC\" Text=\"Button 1\" \/>\n                &lt;Button BackgroundColor=\"#FAEBD7\" Text=\"Button 2\" \/>\n                &lt;Button BackgroundColor=\"#FFF0F5\" Text=\"Button 3\" \/>\n                &lt;Button BackgroundColor=\"#FFE4E1\" Text=\"Button 4\" \/>\n            &lt;\/toolkit:UniformItemsLayout>\n\n            &lt;Label Text=\"UniformItemsLayout with MaxColumns=2 and MaxRows=2\" \/>\n            &lt;toolkit:UniformItemsLayout\n                x:Name=\"UniformItemsLayout_MaxRows2MaxColumns2\"\n                MaxColumns=\"2\"\n                MaxRows=\"2\">\n                &lt;Button BackgroundColor=\"#E6E6FA\" Text=\"Button 1\" \/>\n                &lt;Button BackgroundColor=\"#D8BFD8\" Text=\"Button 2\" \/>\n                &lt;Button BackgroundColor=\"#DDA0DD\" Text=\"Button 3\" \/>\n                &lt;Button BackgroundColor=\"#EE82EE\" Text=\"Button 4\" \/>\n            &lt;\/toolkit:UniformItemsLayout>\n\n            &lt;Label Text=\"UniformItemsLayout with MaxRows=1\" \/>\n            &lt;toolkit:UniformItemsLayout x:Name=\"UniformItemsLayout_MaxRows1\" MaxRows=\"1\">\n                &lt;Button BackgroundColor=\"#FFDEAD\" Text=\"Button 1\" \/>\n                &lt;Button BackgroundColor=\"#D2B48C\" Text=\"Button 2\" \/>\n                &lt;Button BackgroundColor=\"#F4A460\" Text=\"Button 3\" \/>\n                &lt;Button BackgroundColor=\"#B8860B\" Text=\"Button 4\" \/>\n            &lt;\/toolkit:UniformItemsLayout>\n\n            &lt;Label Text=\"UniformItemsLayout with MaxColumns=1\" \/>\n            &lt;toolkit:UniformItemsLayout x:Name=\"UniformItemsLayout_MaxColumns1\" MaxColumns=\"1\">\n                &lt;Button BackgroundColor=\"#D3D3D3\" Text=\"Button 1\" \/>\n                &lt;Button BackgroundColor=\"#A9A9A9\" Text=\"Button 2\" \/>\n                &lt;Button BackgroundColor=\"#808080\" Text=\"Button 3\" \/>\n                &lt;Button BackgroundColor=\"#696969\" Text=\"Button 4\" \/>\n            &lt;\/toolkit:UniformItemsLayout>\n\n        &lt;\/VerticalStackLayout>\n    &lt;\/ScrollView>\n\n&lt;\/ContentPage><\/pre>\n\n\n\n<p>As in the above <strong>MainPage.xaml<\/strong> i have used four <strong><strong>UniformItemsLayout<\/strong><\/strong> :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em><strong>UniformItemsLayout with default settings :<\/strong><\/em>  Here there is no Column and Row limit set so based on numbers of children <strong>MaxColumns<\/strong> and <strong>MaxRows<\/strong> will set.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em><strong>UniformItemsLayout with MaxColumns=2 and MaxRows=2 :<\/strong><\/em> Here only 4 children will display because <strong>MaxColumns<\/strong> is set to 2 and <strong>MaxRows<\/strong> is set to 2.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>UniformItemsLayout with MaxRows=1 :<\/em><\/strong> All children will arrange in 1 row.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>UniformItemsLayout with MaxColumns=1 :<\/em> <\/strong>All children will arrange in 1 column.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3.2 &#8211; MainPage.xaml.cs<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace MAUIUniformItemsLayoutSample;\n\npublic partial class MainPage : ContentPage\n{\n    public MainPage()\n    {\n        InitializeComponent();\n    }\n}<\/pre>\n\n\n\n<p>Now, We have completed the coding, Let\u2019s try to run the application.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>4 &#8211; Result<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"2796\" style=\"aspect-ratio: 1290 \/ 2796;\" width=\"1290\" controls muted src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/UniformItemsLayout.mp4\"><\/video><\/figure>\n\n\n\n<p>That\u2019s all for now!<\/p>\n\n\n\n<p>You can check the full source code <strong><a href=\"https:\/\/github.com\/Alam-Ashraf\/MAUIUniformItemsLayoutSample\" target=\"_blank\" rel=\"noopener\" title=\"\">here<\/a>.<\/strong><\/p>\n\n\n\n<p>Happy Coding!<strong> \ud83d\ude00<\/strong><\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-16018d1d wp-block-buttons-is-layout-flex\"><\/div>\n\n\n\n<div style=\"height:34px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You may also like<\/strong><\/p>\n\n\n\n<div class=\"wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2022\/11\/28\/biometric-authentication-in-xamarin-forms\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-1024x696.png\" alt=\"Biometric authentication in Xamarin\" class=\"wp-image-346\" width=\"512\" height=\"348\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-1024x696.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-300x204.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-768x522.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication-850x578.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/XamarinFormsBiometricAuthentication.png 1236w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">Implementation Of Biometric Authentication in Xamarin Forms<\/p>\n<\/div>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\"><div class=\"wp-block-image is-style-default\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2022\/11\/24\/carouselview-with-indicatorview\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/CarouselViewWithIndicatorView-1024x1003.png\" alt=\"CarouselView With IndicatorView\" class=\"wp-image-281\" width=\"512\" height=\"502\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/CarouselViewWithIndicatorView-1024x1003.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/CarouselViewWithIndicatorView-300x294.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/CarouselViewWithIndicatorView-768x752.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/CarouselViewWithIndicatorView-850x832.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/CarouselViewWithIndicatorView.png 1244w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">Xamarin Forms \u2013 The Latest CarouselView with IndicatorView<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>UniformItemsLayout&nbsp;in&nbsp;MAUI&nbsp;Community Toolkit is a layout where all rows and columns will have the same size. UniformItemsLayout is similar to Grid. For positioning the child in a particular cell we no need to specify row and column index in UniformItemsLayout like in Grid, It will automatically positioned child in row and column. In this article, I\u2019m&#8230;<\/p>\n","protected":false},"author":1,"featured_media":522,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4,37],"tags":[41,38,39,40],"class_list":["post-518","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnetmaui","category-maui-community-toolkit","tag-grid","tag-how-to-use-uniformitemslayout-in-maui","tag-maui-community-toolkit","tag-uniformitemslayout"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/comments?post=518"}],"version-history":[{"count":8,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/518\/revisions"}],"predecessor-version":[{"id":746,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/518\/revisions\/746"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media\/522"}],"wp:attachment":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media?parent=518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/categories?post=518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/tags?post=518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}