LazyView

Met het besturingselement LazyView kunt u de initialisatie van een View uitstellen. U moet het type van de View opgeven die u wilt laten weergeven, met behulp van het XAML-naamruimtekenmerk x:TypeArguments, en de initialisatie ervan verwerken met de methode LoadViewAsync. De HasLazyViewLoaded eigenschap kan worden onderzocht om te bepalen wanneer de LazyView eigenschap is geladen.

Syntax

Inclusief de XAML-naamruimte

Als u de toolkit in XAML wilt gebruiken, moet de volgende xmlns worden toegevoegd aan uw pagina of weergave:

xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"

Daarom volgt het volgende:

<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>

Zou als volgt worden gewijzigd om de xmlns op te nemen:

<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>

De LazyView gebruiken

<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>

In de code achter kunt u de weergave laden door de LoadViewAsync methode aan te roepen.

async void LoadLazyView_Clicked(object sender, EventArgs e)
{
    await LazyUserAction.LoadViewAsync();
}

Eigenschappen

Property Type Description
HasLazyViewLoaded Boolean Haalt de geladen status van de LazyView op.

Methods

Property Retourtype Description
LoadViewAsync ValueTask Initialiseer de View.

Examples

Je kunt een voorbeeld van hoe deze functie werkt vinden in de .NET MAUI Community Toolkit Sample Application.

API

U vindt de broncode voor LazyView in de .NET MAUI Community Toolkit GitHub opslagplaats.