ProgressBarAnimationBehavior
Das Animationsverhalten ProgressBar animiert einen ProgressBar
von seinem aktuellen Fortschrittswert zu einem angegebenen Wert über einen bestimmten Zeitraum. Die Methode akzeptiert einen Statuswert Double
, eine Dauer uint
in Millisekunden und einen Enumerationswert Easing
.
Wichtig
.NET MAUI Community Toolkit Behaviors legt den BindingContext
eines Verhaltens nicht fest, da Verhalten über Stile freigegeben und auf mehrere Steuerelemente angewendet werden können. Weitere Informationen finden Sie unter .NET MAUI Behaviors.
Syntax
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 von ProgressBarAnimationBehavior
ProgressBarAnimationBehavior
kann wie folgt in XAML verwendet werden:
<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#
ProgressBarAnimationBehavior
kann wie folgt in C# verwendet werden:
class ProgressBarAnimationBehaviorPage : ContentPage
{
public ProgressBarAnimationBehaviorPage()
{
var progressBar = new ProgressBar();
var behavior = new ProgressBarAnimationBehavior()
{
Progress = 0.75,
Length = 250
};
progressBar.Behaviors.Add(behavior);
Content = progressBar;
}
}
C#-Markup
Das Paket CommunityToolkit.Maui.Markup
bietet eine viel präzisere Möglichkeit, dieses Behavior
in C# zu verwenden.
using CommunityToolkit.Maui.Markup;
class ProgressBarAnimationBehaviorPage : ContentPage
{
public ProgressBarAnimationBehaviorPage()
{
Content = new ProgressBar()
.Behaviors(new ProgressBarAnimationBehavior
{
Progress = 0.75,
Length = 250
});
}
}
Eigenschaften
Eigenschaft | Typ | Beschreibung |
---|---|---|
Status | Double | Neuer Fortschrittswert, der als Prozentsatz animiert wird, wobei 1 für 100 % steht und 0,75 für 75 %. |
Length | uint | Dauer in Millisekunden |
Beschleunigung | enum | Mit enum , das Easing steuert, können Sie eine Übertragungsfunktion angeben, die steuert, wie Animationen beschleunigt oder verlangsamt werden. Weitere Details zur Beschleunigung finden Sie hier. |
Beispiele
Sie finden ein Beispiel für dieses Verhalten in Aktion in der Beispielanwendung für das .NET MAUI Community Toolkit.
API
Sie finden den Quellcode für ProgressBarAnimationBehavior
über das GitHub-Repository für das .NET MAUI Community Toolkit.
.NET MAUI Community Toolkit