Skip to content

Commit 07558e4

Browse files
authored
Adds IsLoading bindable property to pages and fixes SelectViewModelCommand (#45)
In Maui, the `IsBusy` property on pages now shows a loading indicator with no way to override that behavior. Since implementing apps may want their own loading indicator, this creates a new `IsLoading` property which the implementing app can choose to forward to `IsBusy` if it wants. Also fixes the SelectViewModelCommand so it passes the model instead of the view model to the `CanExecute` callback.
1 parent 8a9e0c8 commit 07558e4

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Float.Core/Commands/SelectViewModelCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public event EventHandler CanExecuteChanged
5252
/// <inheritdoc />
5353
public bool CanExecute(object parameter)
5454
{
55-
return parameter is ViewModel<T> && command.CanExecute(parameter);
55+
return parameter is ViewModel<T> vm && command.CanExecute(vm.UnderlyingModel);
5656
}
5757

5858
/// <summary>

Float.Core/UI/BaseContentPage.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ public abstract class BaseContentPage : ContentPage
2121
/// </summary>
2222
public static readonly BindableProperty ErrorProperty = BindableProperty.Create(nameof(Error), typeof(Exception), typeof(ContentPage), null);
2323

24+
/// <summary>
25+
/// Binding for the IsLoading property.
26+
/// </summary>
27+
public static readonly BindableProperty IsLoadingProperty = BindableProperty.Create(nameof(IsLoading), typeof(bool), typeof(BaseContentPage));
28+
29+
/// <summary>
30+
/// Gets or sets a value indicating whether the page should show a loading indicator.
31+
/// </summary>
32+
/// <value>Whether the page should show the loading indicator.</value>
33+
public bool IsLoading
34+
{
35+
get => (bool)GetValue(IsLoadingProperty);
36+
set => SetValue(IsLoadingProperty, value);
37+
}
38+
2439
/// <summary>
2540
/// Gets or sets the current error on the page.
2641
/// </summary>
@@ -52,7 +67,7 @@ protected override void OnBindingContextChanged()
5267
if (BindingContext is ViewModels.IPageViewModel viewModel)
5368
{
5469
this.SetBinding(TitleProperty, nameof(viewModel.Title));
55-
this.SetBinding(IsBusyProperty, nameof(viewModel.IsLoading));
70+
this.SetBinding(IsLoadingProperty, nameof(viewModel.IsLoading));
5671
this.SetBinding(ErrorProperty, nameof(viewModel.Error), BindingMode.TwoWay);
5772
}
5873
}
@@ -73,8 +88,8 @@ protected override void OnPropertyChanged(string propertyName = null)
7388
base.OnPropertyChanged(propertyName);
7489
switch (propertyName)
7590
{
76-
case nameof(IsBusy):
77-
if (IsBusy)
91+
case nameof(IsLoading):
92+
if (IsLoading)
7893
{
7994
OnStartLoading();
8095
}

0 commit comments

Comments
 (0)