Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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.
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 @@ -100,6 +100,7 @@ public override string ToString()
new GalleryPageFactory(() => new GraphicsViewControlPage(), "GraphicsView Feature Matrix"),
new GalleryPageFactory(() => new EditorControlPage(), "Editor Feature Matrix"),
new GalleryPageFactory(() => new ToolbarFeaturePage(), "Toolbar Feature Matrix"),
new GalleryPageFactory(() => new LayoutControlPage(), "ScrollView With LayoutOptions Feature Matrix"),
};

public CorePageView(Page rootPage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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.LayoutMainPage"
x:DataType="local:LayoutViewModel"
Title="LayoutPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Options"
Clicked="NavigateToOptionsPage_Clicked"
AutomationId="Options"/>
</ContentPage.ToolbarItems>
<Grid RowDefinitions="*,Auto"
ColumnDefinitions="*,*"
Padding="0,10"
RowSpacing="10"
ColumnSpacing="3">

<ScrollView Grid.Row="0"
Grid.ColumnSpan="2"
x:Name="MyScrollView"
HeightRequest="{Binding HeightRequest}"
WidthRequest="{Binding WidthRequest}"
Orientation="{Binding Orientation}"
HorizontalScrollBarVisibility="Never"
VerticalScrollBarVisibility="Never"
BackgroundColor="Lavender"/>
<Button Text="StackLayout"
Grid.Row="1"
Grid.Column="0"
Clicked="OnScrollViewWithStackLayoutClicked"
AutomationId="StackLayoutButton"
WidthRequest="200"/>
<Button Text="Grid"
Grid.Row="1"
Grid.Column="1"
Clicked="OnGridWithChildrenClicked"
AutomationId="GridButton"
WidthRequest="200"/>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample;

public class LayoutControlPage : NavigationPage
{
private LayoutViewModel _viewModel;
public LayoutControlPage()
{
_viewModel = new LayoutViewModel();

PushAsync(new LayoutMainPage(_viewModel));
}
}

public partial class LayoutMainPage : ContentPage
{
private LayoutViewModel _viewModel;

public LayoutMainPage(LayoutViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;
InitializeContent();
}
protected override void OnAppearing()
{
base.OnAppearing();
InitializeContent();
}

private void InitializeContent()
{
var defaultLayout = new VerticalStackLayout
{
BackgroundColor = Colors.LightGray,
Children =
{
new Label { Text = "Welcome to LayoutPage" },
}
};

MyScrollView.Content = defaultLayout;
}

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

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

Creating a new LayoutViewModel instance here discards any configuration changes made on the options page. The existing _viewModel should be reused to preserve the configured layout options.

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

Copilot uses AI. Check for mistakes.

await Navigation.PushAsync(new LayoutOptionsPage(_viewModel));
}

private void OnScrollViewWithStackLayoutClicked(object sender, EventArgs e)
{
Layout layout;

if (_viewModel.Orientation == ScrollOrientation.Horizontal)
{
layout = new HorizontalStackLayout
{
HorizontalOptions = _viewModel.HorizontalOptions,
VerticalOptions = _viewModel.VerticalOptions,
BackgroundColor = Colors.LightGray,
Spacing = 10,
Children =
{
new Label { Text = "StackLayout", VerticalOptions = LayoutOptions.Center },
new Button { Text = "Button1", VerticalOptions = LayoutOptions.Center },
new Button { Text = "Button2", VerticalOptions = LayoutOptions.Center }
}
};
}
else
{
layout = new VerticalStackLayout
{
HorizontalOptions = _viewModel.HorizontalOptions,
VerticalOptions = _viewModel.VerticalOptions,
BackgroundColor = Colors.LightGray,
Spacing = 10,
Children =
{
new Label { Text = "StackLayout", HorizontalOptions = LayoutOptions.Center },
new Button { Text = "Button1", HorizontalOptions = LayoutOptions.Center },
new Button { Text = "Button2", HorizontalOptions = LayoutOptions.Center }
}
};
}

MyScrollView.Content = layout;
}

private void OnGridWithChildrenClicked(object sender, EventArgs e)
{
var grid = new Grid
{
Padding = 15,
BackgroundColor = Colors.LightGray,
HorizontalOptions = _viewModel.HorizontalOptions,
VerticalOptions = _viewModel.VerticalOptions,
RowSpacing = 10,
ColumnSpacing = 10
};

grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star });

grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });

var button1 = new Button { Text = "Button 1", BackgroundColor = Colors.Orange, TextColor = Colors.White };
var button2 = new Button { Text = "Button 2", BackgroundColor = Colors.Blue, TextColor = Colors.White };
var button3 = new Button { Text = "Button 3", BackgroundColor = Colors.Green, TextColor = Colors.White };
var button4 = new Button { Text = "Button 4", BackgroundColor = Colors.Red, TextColor = Colors.White };
var button5 = new Button { Text = "Button 5", BackgroundColor = Colors.Purple, TextColor = Colors.White };
var button6 = new Button { Text = "Button 6", BackgroundColor = Colors.Brown, TextColor = Colors.White };
grid.Add(button1, 0, 0);
grid.Add(button2, 1, 0);
grid.Add(button3, 2, 0);
grid.Add(button4, 0, 1);
grid.Add(button5, 1, 1);
grid.Add(button6, 2, 1);
MyScrollView.Content = grid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?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"
x:Class="Maui.Controls.Sample.LayoutOptionsPage"
Title="LayoutOptionsPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Apply"
Clicked="ApplyButton_Clicked"
AutomationId="Apply"/>
</ContentPage.ToolbarItems>

<Grid Padding="10"
RowSpacing="10"
ColumnSpacing="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<!-- Horizontal Options Label -->
<Label Grid.Row="0"
Grid.ColumnSpan="2"
Text="HorizontalOptions:"
FontAttributes="Bold"/>

<!-- Horizontal Options Buttons -->
<Button Grid.Row="1"
Grid.Column="0"
Text="Fill"
Clicked="OnHorizontalOptionClicked"
AutomationId="HorizontalFill"/>
<Button Grid.Row="1"
Grid.Column="1"
Text="Start"
Clicked="OnHorizontalOptionClicked"
AutomationId="HorizontalStart"/>

<Button Grid.Row="2"
Grid.Column="0"
Text="Center"
Clicked="OnHorizontalOptionClicked"
AutomationId="HorizontalCenter"/>
<Button Grid.Row="2"
Grid.Column="1"
Text="End"
Clicked="OnHorizontalOptionClicked"
AutomationId="HorizontalEnd"/>

<!-- Vertical Options Label -->
<Label Grid.Row="3"
Grid.ColumnSpan="2"
Text="VerticalOptions:"
FontAttributes="Bold"/>

<!-- Vertical Options Buttons -->
<Button Grid.Row="4"
Grid.Column="0"
Text="Fill"
Clicked="OnVerticalOptionClicked"
AutomationId="VerticalFill"/>
<Button Grid.Row="4"
Grid.Column="1"
Text="Start"
Clicked="OnVerticalOptionClicked"
AutomationId="VerticalStart"/>

<Button Grid.Row="5"
Grid.Column="0"
Text="Center"
Clicked="OnVerticalOptionClicked"
AutomationId="VerticalCenter"/>
<Button Grid.Row="5"
Grid.Column="1"
Text="End"
Clicked="OnVerticalOptionClicked"
AutomationId="VerticalEnd"/>

<!-- WidthRequest Label -->
<Label Grid.Row="6"
Grid.ColumnSpan="2"
Text="WidthRequest:"
FontAttributes="Bold"/>

<!-- WidthRequest Buttons -->
<Button Grid.Row="7"
Grid.Column="0"
Text="No Width"
Clicked="OnWidthRequestClicked"
AutomationId="WidthNone"/>
<Button Grid.Row="7"
Grid.Column="1"
Text="350"
Clicked="OnWidthRequestClicked"
AutomationId="Width350"/>

<!-- HeightRequest Label -->
<Label Grid.Row="8"
Grid.ColumnSpan="2"
Text="HeightRequest:"
FontAttributes="Bold"/>

<!-- HeightRequest Buttons -->
<Button Grid.Row="9"
Grid.Column="0"
Text="No Height"
Clicked="OnHeightRequestClicked"
AutomationId="HeightNone"/>
<Button Grid.Row="9"
Grid.Column="1"
Text="300"
Clicked="OnHeightRequestClicked"
AutomationId="Height300"/>

<!-- Orientation Label -->
<Label Grid.Row="10"
Grid.ColumnSpan="2"
Text="Orientation:"
FontAttributes="Bold"/>

<!-- Orientation Buttons -->
<Button Grid.Row="11"
Grid.Column="0"
Text="Vertical"
Clicked="OnOrientationClicked"
AutomationId="OrientationVertical"/>
<Button Grid.Row="11"
Grid.Column="1"
Text="Horizontal"
Clicked="OnOrientationClicked"
AutomationId="OrientationHorizontal"/>
</Grid>
</ContentPage>
Loading
Loading