Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
UniformItemsLayout Är en layout där alla rader och kolumner har samma storlek.
Skapa en UniformItemsLayout
En UniformItemsLayout kan skapas i XAML eller C#:
XAML
Inklusive XAML-namnområdet
För att kunna använda verktygslådan i XAML måste följande xmlns läggas till på sidan eller vyn:
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Därför följande:
<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>
Skulle ändras för att inkludera xmlns på följande sätt:
<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>
Använda 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 }
}
}
};
Anpassa en UniformItemsLayout
En UniformItemsLayout tillåter att begränsa det maximala antalet kolumner och rader:
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 }
}
}
};
Egenskaper
| Fastighet | Type | Description |
|---|---|---|
MaxColumns |
int |
Hämtar eller anger det maximala antalet objekt i en rad. |
MaxRows |
int |
Hämtar eller anger det maximala antalet objekt i en kolumn. |
Exempel
Du hittar ett exempel på den här funktionen i praktiken i .NET MAUI Community Toolkit Sample Application.
API
Källkoden för UniformItemsLayout finns på lagringsplatsen .NET MAUI Community Toolkit GitHub.
.NET MAUI Community Toolkit