Nota
O acesso a esta página requer autorização. Pode tentar iniciar sessão ou alterar os diretórios.
O acesso a esta página requer autorização. Pode tentar alterar os diretórios.
O UniformItemsLayout é uma disposição em que todas as linhas e colunas têm o mesmo tamanho.
Criar um UniformItemsLayout
Um UniformItemsLayout pode ser criado em XAML ou C#:
XAML
Incluindo o namespace XAML
Para usar o kit de ferramentas em XAML, a seguinte xmlns precisa ser adicionada à sua página ou vista.
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Por conseguinte, o seguinte:
<ContentPage
x:Class="CommunityToolkit.Maui.Sample.Pages.MyPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
</ContentPage>
Seria modificado para incluir o xmlns da seguinte forma:
<ContentPage
x:Class="CommunityToolkit.Maui.Sample.Pages.MyPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
</ContentPage>
Usando o UniformItemsLayout
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="MyProject.MyContentPage">
<toolkit:UniformItemsLayout>
<BoxView BackgroundColor="Blue" HeightRequest="25" WidthRequest="25"/>
<BoxView BackgroundColor="Yellow" HeightRequest="25" WidthRequest="25"/>
<BoxView BackgroundColor="Red" HeightRequest="25" WidthRequest="25"/>
<BoxView BackgroundColor="Black" HeightRequest="25" WidthRequest="25"/>
</toolkit:UniformItemsLayout>
</ContentPage>
C#
using CommunityToolkit.Maui.Views;
var page = new ContentPage
{
Content = new UniformItemsLayout
{
Children =
{
new BoxView { HeightRequest = 25, WidthRequest = 25, BackgroundColor = Colors.Blue },
new BoxView { HeightRequest = 25, WidthRequest = 25, BackgroundColor = Colors.Yellow },
new BoxView { HeightRequest = 25, WidthRequest = 25, BackgroundColor = Colors.Red },
new BoxView { HeightRequest = 25, WidthRequest = 25, BackgroundColor = Colors.Black }
}
}
};
Personalizar um UniformItemsLayout
An UniformItemsLayout permite limitar o número máximo de colunas e linhas:
XAML
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="MyProject.MyContentPage">
<toolkit:UniformItemsLayout MaxRows="1" MaxColumns="1">
<BoxView BackgroundColor="Blue" HeightRequest="25" WidthRequest="25"/>
<BoxView BackgroundColor="Yellow" HeightRequest="25" WidthRequest="25"/>
<BoxView BackgroundColor="Red" HeightRequest="25" WidthRequest="25"/>
<BoxView BackgroundColor="Black" HeightRequest="25" WidthRequest="25"/>
</toolkit:UniformItemsLayout>
</ContentPage>
C#
using CommunityToolkit.Maui.Views;
var page = new ContentPage
{
Content = new UniformItemsLayout
{
MaxRows = 1,
MaxColumns = 1,
Children =
{
new BoxView { HeightRequest = 25, WidthRequest = 25, BackgroundColor = Colors.Blue },
new BoxView { HeightRequest = 25, WidthRequest = 25, BackgroundColor = Colors.Yellow },
new BoxView { HeightRequest = 25, WidthRequest = 25, BackgroundColor = Colors.Red },
new BoxView { HeightRequest = 25, WidthRequest = 25, BackgroundColor = Colors.Black }
}
}
};
Propriedades
| Propriedade | Tipo | Description |
|---|---|---|
MaxColumns |
int |
Obtém ou define o número máximo de itens numa linha. |
MaxRows |
int |
Obtém ou define o número máximo de itens numa coluna. |
Exemplos
Você pode encontrar um exemplo desse recurso em ação no .NET MAUI Community Toolkit Sample Application.
API
Você pode encontrar o código-fonte para UniformItemsLayout no repositório GitHub do .NET MAUI Community Toolkit.
.NET MAUI Community Toolkit