{"id":438,"date":"2022-12-07T14:25:42","date_gmt":"2022-12-07T14:25:42","guid":{"rendered":"https:\/\/learnmobiledevelopment.com\/?p=438"},"modified":"2023-01-18T16:43:58","modified_gmt":"2023-01-18T16:43:58","slug":"docklayout-in-maui","status":"publish","type":"post","link":"https:\/\/learnmobiledevelopment.com\/index.php\/2022\/12\/07\/docklayout-in-maui\/","title":{"rendered":"How to use DockLayout in MAUI"},"content":{"rendered":"\n<p>The Xamarin.CommunityToolkit <strong><strong>DockLayout&nbsp;in MAUI<\/strong><\/strong> is a layout where children can be <strong>docked<\/strong> to the sides of the layout container. Children are docked at one of 4 possible docking positions <em><strong>Top<\/strong><\/em>,&nbsp;<em><strong>Bottom<\/strong><\/em>,&nbsp;<em><strong>Left<\/strong><\/em>&nbsp;or&nbsp;<em><strong>Right<\/strong><\/em>. Child that are not explicitly docked or (with &#8216;<strong><em>None<\/em><\/strong>&#8216;) are displayed at the center.<\/p>\n\n\n\n<p>In this article, I\u2019m going to show you how to use&nbsp;<strong>DockLayout&nbsp;in MAUI<\/strong>&nbsp;<strong>Community Toolkit<\/strong>.<\/p>\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 <strong><a href=\"https:\/\/www.nuget.org\/packages\/CommunityToolkit.Maui\/\" target=\"_blank\" rel=\"noopener\" title=\"\">CommunityToolkit.Maui<\/a><\/strong> 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 &#8211; 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 MAUIDockLayoutSample;\n\npublic static class MauiProgram\n{\n\tpublic static MauiApp CreateMauiApp()\n\t{\n\t\tvar builder = MauiApp.CreateBuilder();\n\t\tbuilder\n\t\t\t.UseMauiApp&lt;App>()\n\t\t\t.UseMauiCommunityToolkit()\n            .ConfigureFonts(fonts =>\n\t\t\t{\n\t\t\t\tfonts.AddFont(\"OpenSans-Regular.ttf\", \"OpenSansRegular\");\n\t\t\t\tfonts.AddFont(\"OpenSans-Semibold.ttf\", \"OpenSansSemibold\");\n\t\t\t});\n\n#if DEBUG\n\t\tbuilder.Logging.AddDebug();\n#endif\n\n\t\treturn builder.Build();\n\t}\n}<\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3 &#8211; Setting up the UI<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3.1 &#8211; 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 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             x:Class=\"MAUIDockLayoutSample.MainPage\">\n\n    &lt;toolkit:DockLayout VerticalOptions=\"FillAndExpand\" HorizontalOptions=\"FillAndExpand\">\n\n        &lt;StackLayout toolkit:DockLayout.DockPosition=\"Top\" BackgroundColor=\"#ffcc61\" HeightRequest=\"70\"> \n            &lt;Label Text=\"Header\" TextColor=\"Black\" FontSize=\"Large\" FontAttributes=\"Bold\" HorizontalOptions=\"Center\" VerticalOptions=\"CenterAndExpand\"\/>\n        &lt;\/StackLayout>\n        &lt;StackLayout toolkit:DockLayout.DockPosition=\"Bottom\" BackgroundColor=\"#cdaeb4\" HeightRequest=\"70\"> \n            &lt;Label Text=\"Footer\" TextColor=\"Black\" FontSize=\"Large\" FontAttributes=\"Bold\" HorizontalOptions=\"Center\" VerticalOptions=\"CenterAndExpand\"\/>\n        &lt;\/StackLayout>\n         &lt;StackLayout toolkit:DockLayout.DockPosition=\"Left\" BackgroundColor=\"#83888e\" WidthRequest=\"80\"> \n            &lt;Label Text=\"Left\" TextColor=\"Black\" FontSize=\"Large\" FontAttributes=\"Bold\" HorizontalOptions=\"Center\" VerticalOptions=\"CenterAndExpand\"\/>\n        &lt;\/StackLayout>\n         &lt;StackLayout toolkit:DockLayout.DockPosition=\"Right\" BackgroundColor=\"#abc8c2\" WidthRequest=\"80\" HorizontalOptions=\"FillAndExpand\"> \n            &lt;Label Text=\"Right\" TextColor=\"Black\" FontSize=\"Large\" FontAttributes=\"Bold\" HorizontalOptions=\"Center\" VerticalOptions=\"CenterAndExpand\"\/>\n        &lt;\/StackLayout>\n         &lt;Image\n             Source=\"dotnet_bot.png\"\n             HeightRequest=\"180\"\n             WidthRequest=\"180\"\n             HorizontalOptions=\"CenterAndExpand\"\n             VerticalOptions=\"CenterAndExpand\"\n             \/>\n    &lt;\/toolkit:DockLayout>\n    \n&lt;\/ContentPage><\/pre>\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 MAUIDockLayoutSample;\n\npublic partial class MainPage : ContentPage\n{\n    public MainPage()\n    {\n\tInitializeComponent();\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 src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/DockLayout.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\/MAUIDockLayoutSample\" 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 style=\"height:35px\" 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\/20\/internet-connection-status\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/InternetConnStatus-1024x486.png\" alt=\"InternetConnStatus\" class=\"wp-image-120\" width=\"512\" height=\"243\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/InternetConnStatus-1024x486.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/InternetConnStatus-300x142.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/InternetConnStatus-768x364.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/InternetConnStatus-850x403.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/InternetConnStatus.png 1218w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">How to check internet connection continuously 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-full is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2023\/01\/08\/field-modifiers-in-maui\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/FieldModifier.jpg\" alt=\"Field Modifiers in MAUI\" class=\"wp-image-666\" width=\"248\" height=\"147\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/FieldModifier.jpg 496w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/FieldModifier-300x178.jpg 300w\" sizes=\"auto, (max-width: 248px) 100vw, 248px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">How to use Field Modifiers in MAUI<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Xamarin.CommunityToolkit DockLayout&nbsp;in MAUI is a layout where children can be docked to the sides of the layout container. Children are docked at one of 4 possible docking positions Top,&nbsp;Bottom,&nbsp;Left&nbsp;or&nbsp;Right. Child that are not explicitly docked or (with &#8216;None&#8216;) are displayed at the center. In this article, I\u2019m going to show you how to use&nbsp;DockLayout&nbsp;in&#8230;<\/p>\n","protected":false},"author":1,"featured_media":445,"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],"tags":[33,31,32,34],"class_list":["post-438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnetmaui","tag-docklayout-in-net-maui","tag-docklayout-in-maui","tag-how-to-use-docklayout-in-maui","tag-xamarin-communitytoolkit"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/438","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=438"}],"version-history":[{"count":13,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/438\/revisions"}],"predecessor-version":[{"id":752,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/438\/revisions\/752"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media\/445"}],"wp:attachment":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media?parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/categories?post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/tags?post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}