次の方法で共有


ProgressBarAnimationBehavior

ProgressBar アニメーション動作は、ProgressBar を現在の Progress 値から指定された値まで時間の経過とともにアニメーション化します。 このメソッドは、 Double progress 値、uint 期間 (ミリ秒単位)、Easing 列挙値を受け取ります。

重要

.NET MAUI Community Toolkit のビヘイビアーでは、ビヘイビアーの BindingContext は設定されません。ビヘイビアーはスタイルを利用して共有し、複数のコントロールに適用できるためです。 詳細については、「.NET MAUI のビヘイビアー」を参照してください

構文

XAML

XAML 名前空間を含める

XAML でこのツールキットを使用するには、次の xmlns をページまたはビューに追加する必要があります。

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

したがって、以下のコードは、

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

次のように、xmlns を含むように変更されます。

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

ProgressBarAnimationBehavior の使用

ProgressBarAnimationBehavior は、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#

ProgressBarAnimationBehavior は、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;
    }
}

C# Markup

この CommunityToolkit.Maui.Markup パッケージを使うと、より簡潔な方法でこの Behavior を C# で使用できます。

using CommunityToolkit.Maui.Markup;

class ProgressBarAnimationBehaviorPage : ContentPage
{
    public ProgressBarAnimationBehaviorPage()
    {
        Content = new ProgressBar()
        .Behaviors(new ProgressBarAnimationBehavior
        {
            Progress = 0.75,
            Length = 250
        });           
    }
}

Properties

プロパティ タイプ 説明
進行状況 倍精度浮動小数点型 アニメーション化する新しい Progress 値 (パーセンテージ)。1 が 100% なので、0.75 は 75% になります
Length uint 実行時間 (ミリ秒)
イージング enum Easing を制御する enum を使用すると、アニメーションの速度の上げ下げを制御する転送関数を指定できます。 イージングの詳細については、こちらをご覧ください

このビヘイビアーの動作の例は .NET MAUI Community Toolkit サンプル アプリケーションで確認できます。

API

ProgressBarAnimationBehavior のソース コードは、.NET MAUI Community Toolkit の GitHub リポジトリにあります。