Wednesday, July 6, 2022

StackLayout in .Net MAUI

 Stacking views in a vertical or horizontal list is a common design for user interfaces. Stacking views in a vertical or horizontal list is a common design for user interfaces.

In .NET MAUI, you can add views to a StackLayout in C# code or in XAML. 

Example:

XML

<StackLayout x:Name="myStack"> </StackLayout>

c#

public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); var a = new BoxView { BackgroundColor = Colors.Silver, HeightRequest = 30 }; var b = new BoxView { BackgroundColor = Colors.Blue, HeightRequest = 30 }; var c = new BoxView { BackgroundColor = Colors.Gray, HeightRequest = 30 }; myStack.Children.Add(a); myStack.Children.Add(b); myStack.Children.Add(c); } }

To do the same thing in XAML, nest the children inside the StackLayout tags. 

<StackLayout> <BoxView Color="Silver" /> <BoxView Color="Blue" /> <BoxView Color="Gray" /> </StackLayout>

No comments:

Post a Comment

If you’re using Visual Studio to build your .NET MAUI app on a Mac, locating the IPA (iOS App Package) file can be a bit tricky

  If you’re using   Visual Studio   to build your   .NET MAUI   app on a   Mac , locating the   IPA (iOS App Package)   file can be a bit tr...