Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public override string ToString()
new GalleryPageFactory(() => new ScrollViewControlPage(), "ScrollView Feature Matrix"),
new GalleryPageFactory(() => new GraphicsViewControlPage(), "GraphicsView Feature Matrix"),
new GalleryPageFactory(() => new EditorControlPage(), "Editor Feature Matrix"),
new GalleryPageFactory(() => new StackLayoutControlPage(), "StackLayout Feature Matrix"),
};

public CorePageView(Page rootPage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?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:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.StackLayoutControlMainPage"
x:DataType="local:StackLayoutViewModel"
Title="StackLayoutControlPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Options"
Clicked="NavigateToOptionsPage_Clicked"
AutomationId="Options"/>
</ContentPage.ToolbarItems>

<VerticalStackLayout Padding="10"
Spacing="15">
<!-- Show only HorizontalStackLayout examples when horizontal is selected -->
<VerticalStackLayout IsVisible="{Binding IsHorizontalVisible}">
<!-- Heading for spacing example -->
<Label Text="Space between child views"
FontAttributes="Bold"
FontSize="14"
AutomationId="LabelSpacing"
Margin="0,10,0,0"/>
<HorizontalStackLayout
FlowDirection="{Binding FlowDirection}"
Margin="20"
HeightRequest="200"
Spacing="{Binding Spacing}">
<Label Text="Start"
BackgroundColor="Gray"
VerticalOptions="Start"/>
<Label Text="Center"
BackgroundColor="Gray"
VerticalOptions="Center"/>
<Label Text="End"
BackgroundColor="Gray"
VerticalOptions="End"/>
<Label Text="Fill"
BackgroundColor="Gray"
VerticalOptions="Fill"/>
</HorizontalStackLayout>
<!-- Heading for nested horizontal stack example -->
<Label Text="Nest HorizontalStackLayout objects"
FontAttributes="Bold"
FontSize="14"
Margin="0,10,0,0"/>
<HorizontalStackLayout FlowDirection="{Binding FlowDirection}"
Margin="20"
Spacing="{Binding Spacing}">
<!-- Nested VerticalStackLayouts (Primary/Secondary colors) -->
<Label Text="Primary colors:"/>
<VerticalStackLayout Spacing="{Binding Spacing}">
<Rectangle Fill="Red"
WidthRequest="{Binding RectWidth}"
HeightRequest="{Binding RectHeight}"/>
<Rectangle Fill="Yellow"
WidthRequest="{Binding RectWidth}"
HeightRequest="{Binding RectHeight}"/>
<Rectangle Fill="Blue"
WidthRequest="{Binding RectWidth}"
HeightRequest="{Binding RectHeight}"/>
</VerticalStackLayout>
<Label Text="Secondary colors:"/>
<VerticalStackLayout Spacing="{Binding Spacing}">
<Rectangle Fill="Green"
WidthRequest="{Binding RectWidth}"
HeightRequest="{Binding RectHeight}"/>
<Rectangle Fill="Orange"
WidthRequest="{Binding RectWidth}"
HeightRequest="{Binding RectHeight}"/>
<Rectangle Fill="Purple"
WidthRequest="{Binding RectWidth}"
HeightRequest="{Binding RectHeight}"/>
</VerticalStackLayout>
</HorizontalStackLayout>
</VerticalStackLayout>
<!-- Show only VerticalStackLayout examples when vertical is selected -->
<VerticalStackLayout IsVisible="{Binding IsVerticalVisible}">
<!-- Heading for spacing example -->
<Label Text="Space between child views"
FontAttributes="Bold"
FontSize="14"
Margin="0,10,0,0"/>
<VerticalStackLayout FlowDirection="{Binding FlowDirection}"
Margin="20"
Spacing="{Binding Spacing}">
<!-- Original Microsoft Docs Example -->
<Label Text="Start"
BackgroundColor="Gray"
HorizontalOptions="Start"/>
<Label Text="Center"
BackgroundColor="Gray"
HorizontalOptions="Center"/>
<Label Text="End"
BackgroundColor="Gray"
HorizontalOptions="End"/>
<Label Text="Fill"
BackgroundColor="Gray"
HorizontalOptions="Fill"/>
</VerticalStackLayout>
<!-- Heading for nested vertical stack example -->
<Label Text="Nest VerticalStackLayout objects"
FontAttributes="Bold"
FontSize="14"
Margin="0,10,0,0"/>
<VerticalStackLayout FlowDirection="{Binding FlowDirection}"
Margin="20"
Spacing="{Binding Spacing}">
<!-- Nested HorizontalStackLayouts (Primary colors with Borders) -->
<Label Text="Primary colors"/>
<Border Stroke="Black"
Padding="5">
<HorizontalStackLayout Spacing="{Binding Spacing}">
<Rectangle Fill="Red"
HeightRequest="{Binding RectHeight}"
WidthRequest="{Binding RectWidth}"/>
<Label Text="Red"
FontSize="18"/>
</HorizontalStackLayout>
</Border>
<Border Stroke="Black"
Padding="5">
<HorizontalStackLayout Spacing="{Binding Spacing}">
<Rectangle Fill="Yellow"
HeightRequest="{Binding RectHeight}"
WidthRequest="{Binding RectWidth}"/>
<Label Text="Yellow"
FontSize="18"/>
</HorizontalStackLayout>
</Border>
<Border Stroke="Black"
Padding="5">
<HorizontalStackLayout Spacing="{Binding Spacing}">
<Rectangle Fill="Blue"
HeightRequest="{Binding RectHeight}"
WidthRequest="{Binding RectWidth}"/>
<Label Text="Blue"
FontSize="18"/>
</HorizontalStackLayout>
</Border>
</VerticalStackLayout>
</VerticalStackLayout>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Maui.Controls.Sample;
public partial class StackLayoutControlPage : NavigationPage
{
private StackLayoutViewModel _viewModel;

public StackLayoutControlPage()
{
_viewModel = new StackLayoutViewModel();
PushAsync(new StackLayoutControlMainPage(_viewModel));
}
}
public partial class StackLayoutControlMainPage : ContentPage
{
private StackLayoutViewModel _viewModel;

public StackLayoutControlMainPage(StackLayoutViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
}

private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
BindingContext = _viewModel = new StackLayoutViewModel();
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new StackLayoutViewModel instance discards any changes made in the current view model. This should retain the existing _viewModel state instead of creating a new instance.

Suggested change
BindingContext = _viewModel = new StackLayoutViewModel();
BindingContext = _viewModel;

Copilot uses AI. Check for mistakes.
await Navigation.PushAsync(new StackLayoutOptionsPage(_viewModel));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.StackLayoutOptionsPage"
x:DataType="local:StackLayoutViewModel"
Title="StackLayoutOptionsPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Apply"
Clicked="ApplyButton_Clicked"
AutomationId="Apply"/>
</ContentPage.ToolbarItems>

<VerticalStackLayout Padding="10"
Spacing="5">
<Label Text="Choose Layout Orientation:"
FontAttributes="Bold"
FontSize="16"/>
<HorizontalStackLayout>
<RadioButton Content="Horizontal"
IsChecked="{Binding IsHorizontal, Mode=TwoWay}"
GroupName="OrientationGroup"
AutomationId="RadioHorizontal"/>
<RadioButton Content="Vertical"
IsChecked="{Binding IsVertical, Mode=TwoWay}"
GroupName="OrientationGroup"
Margin="20,0,0,0"
AutomationId="RadioVertical"/>
</HorizontalStackLayout>

<!-- IsVisible Option -->
<HorizontalStackLayout Spacing="10"
VerticalOptions="Center">
<Label Text="IsVisible"
VerticalOptions="Center"/>
<CheckBox IsChecked="{Binding IsVisible, Mode=TwoWay}"
AutomationId="CheckBoxIsVisible"/>
</HorizontalStackLayout>

<!-- RTL FlowDirection Option -->
<HorizontalStackLayout Spacing="10"
VerticalOptions="Center">
<Label Text="RTL"
VerticalOptions="Center"/>
<CheckBox IsChecked="{Binding IsRtl, Mode=TwoWay}"
AutomationId="CheckBoxIsRtl"/>
</HorizontalStackLayout>

<!-- Spacing Option -->
<HorizontalStackLayout Spacing="10"
VerticalOptions="Center">
<Label Text="Spacing"
VerticalOptions="Center"/>
<Entry Text="{Binding Spacing, Mode=TwoWay}"
Keyboard="Numeric"
WidthRequest="80"
AutomationId="EntrySpacing"/>
</HorizontalStackLayout>

<!-- Rectangle Height Option -->
<HorizontalStackLayout Spacing="10"
VerticalOptions="Center">
<Label Text="Height"
VerticalOptions="Center"/>
<Entry Text="{Binding RectHeight, Mode=TwoWay}"
Keyboard="Numeric"
WidthRequest="80"
AutomationId="EntryHeight"/>
</HorizontalStackLayout>

<!-- Rectangle Width Option -->
<HorizontalStackLayout Spacing="10"
VerticalOptions="Center">
<Label Text="Width"
VerticalOptions="Center"/>
<Entry Text="{Binding RectWidth, Mode=TwoWay}"
Keyboard="Numeric"
WidthRequest="80"
AutomationId="EntryWidth"/>
</HorizontalStackLayout>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample;

public partial class StackLayoutOptionsPage : ContentPage
{
private StackLayoutViewModel _viewModel;

public StackLayoutOptionsPage(StackLayoutViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
}

private void ApplyButton_Clicked(object sender, EventArgs e)
{
Navigation.PopAsync();
}
}
Loading
Loading