This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ProgressBar Attached Property to enable progress animation (#352)
* ProgressBar Attached Property to enable progress animation * Fixes remarks on PR * Fix remarks PR * Changes need for new gallery viewmodel * Correct version from before rebase * Update AttachedPropertiesGalleryViewModel.cs * Update ProgressBarAttachedProperties.shared.cs * Update ProgressBarAttachedProperties.shared.cs * Change Attached property to behavior * Update samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj Co-authored-by: Andrei <andrei.misiukevich@gmail.com> * Update src/CommunityToolkit/Xamarin.CommunityToolkit/Behaviors/ProgressBarAnimationBehavior.cs Co-authored-by: Andrei <andrei.misiukevich@gmail.com> * Update src/CommunityToolkit/Xamarin.CommunityToolkit/Xamarin.CommunityToolkit.csproj Co-authored-by: Andrei <andrei.misiukevich@gmail.com> * Update src/CommunityToolkit/Xamarin.CommunityToolkit/Behaviors/ProgressBarAnimationBehavior.cs Co-authored-by: Cfun <15718354+Cfun1@users.noreply.github.com> * Update src/CommunityToolkit/Xamarin.CommunityToolkit/AttachedProperties/ProgressBarAttachedProperties.shared.cs Co-authored-by: Cfun <15718354+Cfun1@users.noreply.github.com> * Remove old attached property and rename new behavior Co-authored-by: Gerald Versluis <gerald@verslu.is> Co-authored-by: Andrei <andrei.misiukevich@gmail.com> Co-authored-by: Cfun <15718354+Cfun1@users.noreply.github.com>
- Loading branch information
1 parent
459fc4e
commit 0d55a63
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
samples/XCT.Sample/Pages/Behaviors/ProgressBarAnimationBehaviorPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:xct="http://xamarin.com/schemas/2020/toolkit" | ||
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages" | ||
xmlns:vm="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.Behaviors" | ||
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Behaviors.ProgressBarAnimationBehaviorPage"> | ||
|
||
<pages:BasePage.BindingContext> | ||
<vm:ProgressBarAnimationBehaviorViewModel /> | ||
</pages:BasePage.BindingContext> | ||
|
||
<StackLayout Padding="{StaticResource ContentPadding}" | ||
Spacing="50" | ||
VerticalOptions="CenterAndExpand"> | ||
<ProgressBar> | ||
<ProgressBar.Behaviors> | ||
<xct:ProgressBarAnimationBehavior AnimateProgress="{Binding Progress}" /> | ||
</ProgressBar.Behaviors> | ||
</ProgressBar> | ||
|
||
<Button Text="Set to 0" Command="{Binding SetTo0Command}" /> | ||
<Button Text="Set to 50" Command="{Binding SetTo50Command}" /> | ||
<Button Text="Set to 100" Command="{Binding SetTo100Command}" /> | ||
</StackLayout> | ||
</pages:BasePage> |
10 changes: 10 additions & 0 deletions
10
samples/XCT.Sample/Pages/Behaviors/ProgressBarAnimationBehaviorPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace Xamarin.CommunityToolkit.Sample.Pages.Behaviors | ||
{ | ||
public partial class ProgressBarAnimationBehaviorPage : BasePage | ||
{ | ||
public ProgressBarAnimationBehaviorPage() | ||
=> InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
samples/XCT.Sample/ViewModels/Behaviors/ProgressBarAnimationBehaviorViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
using Xamarin.CommunityToolkit.ObjectModel; | ||
|
||
namespace Xamarin.CommunityToolkit.Sample.ViewModels.Behaviors | ||
{ | ||
public class ProgressBarAnimationBehaviorViewModel : BaseViewModel | ||
{ | ||
double progress; | ||
ICommand setTo0Command; | ||
ICommand setTo50Command; | ||
ICommand setTo100Command; | ||
|
||
public double Progress | ||
{ | ||
get => progress; | ||
set | ||
{ | ||
progress = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
|
||
public ICommand SetTo0Command => setTo0Command ??= new AsyncCommand(() => SetProgress(0)); | ||
|
||
public ICommand SetTo50Command => setTo50Command ??= new AsyncCommand(() => SetProgress(0.5)); | ||
|
||
public ICommand SetTo100Command => setTo100Command ??= new AsyncCommand(() => SetProgress(1)); | ||
|
||
async Task SetProgress(double | ||
progress) | ||
{ | ||
Progress = progress; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ommunityToolkit/Xamarin.CommunityToolkit/Behaviors/ProgressBarAnimationBehavior.shared.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using Xamarin.CommunityToolkit.Behaviors.Internals; | ||
using Xamarin.Forms; | ||
|
||
namespace Xamarin.CommunityToolkit.Behaviors | ||
{ | ||
public class ProgressBarAnimationBehavior : BaseBehavior<ProgressBar> | ||
{ | ||
/// <summary> | ||
/// Backing BindableProperty for the <see cref="AnimateProgress"/> property. | ||
/// </summary> | ||
public static readonly BindableProperty AnimateProgressProperty = | ||
BindableProperty.CreateAttached(nameof(AnimateProgress), typeof(double), typeof(ProgressBar), 0.0d, propertyChanged: OnAnimateProgressPropertyChanged); | ||
|
||
public double AnimateProgress | ||
{ | ||
get => (double)GetValue(AnimateProgressProperty); | ||
set => SetValue(AnimateProgressProperty, value); | ||
} | ||
|
||
static void OnAnimateProgressPropertyChanged(BindableObject bindable, object oldValue, object newValue) | ||
=> ((ProgressBarAnimationBehavior)bindable).Animate(); | ||
|
||
void Animate() | ||
=> View.ProgressTo(AnimateProgress, 500, Easing.Linear); | ||
} | ||
} |