UniformItemsLayout
UniformItemsLayout
ist ein Layout, in dem alle Zeilen und Spalten dieselbe Größe aufweisen.
Erstellen eines UniformItemsLayout
Ein UniformItemsLayout
kann in XAML oder C# erstellt werden:
XAML
Einbinden des XAML-Namespace
Um das Toolkit in XAML verwenden zu können, muss der folgende xmlns
-Abschnitt zu Ihrer Seite oder Ansicht hinzugefügt werden:
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Der folgende Abschnitt:
<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>
Würde dann geändert werden, um xmlns
einzubinden:
<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>
Verwenden des 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 }
}
}
};
Anpassen eines UniformItemsLayout
Ein UniformItemsLayout
erlaubt es, die maximale Anzahl von Spalten und Zeilen zu begrenzen:
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 }
}
}
};
Eigenschaften
Eigenschaft | Typ | Beschreibung |
---|---|---|
MaxColumns |
int |
Ruft die maximale Anzahl von Elementen in einer Zeile ab oder legt sie fest. |
MaxRows |
int |
Ruft die maximale Anzahl von Elementen in einer Spalte ab oder legt sie fest. |
Beispiele
Sie finden ein Beispiel für dieses Feature in Aktion in der Beispielanwendung für das .NET MAUI Community Toolkit.
API
Sie finden den Quellcode für UniformItemsLayout
über das GitHub-Repository für das .NET MAUI Community Toolkit.
.NET MAUI Community Toolkit