Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Il comportamento di animazione della ProgressBar anima un elemento ProgressBar dal valore di avanzamento corrente fino a un valore specificato nel tempo. Il metodo accetta un Double valore di avanzamento, una uint durata in millisecondi e un Easing valore enum.
Importante
I comportamenti di .NET MAUI Community Toolkit non impostano il BindingContext di un comportamento, perché i comportamenti possono essere condivisi e applicati a più controlli tramite stili. Per altre informazioni, vedere .NET MAUI Comportamenti
Syntax
XAML
Inclusione dello spazio dei nomi XAML
Per usare il toolkit in XAML, è necessario aggiungere le informazioni seguenti xmlns nella pagina o nella visualizzazione:
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Di conseguenza:
<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>
Verrà modificato in modo da includere l'oggetto xmlns come indicato di seguito:
<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>
Utilizzo di ProgressBarAnimationBehavior
Può ProgressBarAnimationBehavior essere usato come segue in 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="MyLittleApp.MainPage"
x:Name="Page">
<Label Text="The ProgressBarAnimationBehavior is a behavior that animates a ProgressBar" />
<ProgressBar>
<ProgressBar.Behaviors>
<toolkit:ProgressBarAnimationBehavior
x:Name="ProgressBarAnimationBehavior"
Progress="{Binding Source={x:Reference Page}, Path=BindingContext.Progress, x:DataType=ContentPage}"
Length="250"/>
</ProgressBar.Behaviors>
</ProgressBar>
</ContentPage>
C#
Può ProgressBarAnimationBehavior essere usato come indicato di seguito in C#:
class ProgressBarAnimationBehaviorPage : ContentPage
{
public ProgressBarAnimationBehaviorPage()
{
var progressBar = new ProgressBar();
var behavior = new ProgressBarAnimationBehavior()
{
Progress = 0.75,
Length = 250
};
progressBar.Behaviors.Add(behavior);
Content = progressBar;
}
}
Linguaggio di markup C#
Il nostro CommunityToolkit.Maui.Markup pacchetto fornisce un modo molto più conciso per usare questo Behavior in C#.
using CommunityToolkit.Maui.Markup;
class ProgressBarAnimationBehaviorPage : ContentPage
{
public ProgressBarAnimationBehaviorPage()
{
Content = new ProgressBar()
.Behaviors(new ProgressBarAnimationBehavior
{
Progress = 0.75,
Length = 250
});
}
}
Proprietà
| Proprietà | Type | Descrizione |
|---|---|---|
| Progress | Double | Nuovo valore di avanzamento a cui applicare l'animazione come percentuale, dove 1 corrisponde al 100%, quindi 0,75 è 75% |
| Length | uint | Durata in millisecondi |
| Allentamento | enum |
enum che controlla Easing, consente di specificare una funzione di temporizzazione che controlla il modo in cui le animazioni accelerano o rallentano. Puoi trovare ulteriori dettagli su Easing qui |
Esempi
È possibile trovare un esempio di questo comportamento in azione nell'applicazione di esempio .NET MAUI Community Toolkit.
API
È possibile trovare il codice sorgente per ProgressBarAnimationBehavior nel repository .NET MAUI Community Toolkit GitHub.
.NET MAUI Community Toolkit