LazyView
Le contrôle LazyView
vous permet de retarder l’initialisation d’un View
. Vous devez fournir le type de View
à afficher, à l’aide de l’attribut d’espace de noms XAML x:TypeArguments
, mais également gérer son initialisation à l’aide de la méthode LoadViewAsync
. La propriété HasLazyViewLoaded
peut être examinée afin de déterminer l’heure du chargement de LazyView
.
Syntaxe
Y compris l’espace de noms XAML
Pour utiliser le kit de ressources dans XAML, le xmlns
suivant doit être ajouté à votre page ou à votre affichage :
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Il en résulte ce qui suit :
<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>
Serait modifié pour inclure le xmlns
de la manière suivante :
<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>
Utilisation de LazyView
<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="CommunityToolkit.Maui.Sample.Pages.Views.LazyViewPage"
xmlns:local="clr-namespace:CommunityToolkit.Maui.Sample.Pages.Views.LazyView"
Title="Lazy View">
<StackLayout>
<toolkit:LazyView x:Name="LazyUserAction" x:TypeArguments="local:LazyTestView" />
<Button Text="Load View Now" Clicked="LoadLazyView_Clicked" />
</StackLayout>
</ContentPage>
Dans votre code-behind, vous pouvez charger la vue en appelant la méthode LoadViewAsync
.
async void LoadLazyView_Clicked(object sender, EventArgs e)
{
await LazyUserAction.LoadViewAsync();
}
Propriétés
Propriété | Type | Description |
---|---|---|
HasLazyViewLoaded | bool | Obtient l’état chargé du LazyView . |
Méthodes
Propriété | Type renvoyé | Description |
---|---|---|
LoadViewAsync | ValueTask | Initialisez le View . |
Exemples
Vous pouvez trouver un exemple d’utilisation de cette fonctionnalité dans l’exemple d’application du kit d’outils de la communauté .NET MAUI.
API
Vous pouvez trouver le code source deLazyView
sur le référentiel du kit de ressources de la communauté .NET MAUI sur GitHub.
.NET MAUI Community Toolkit