I'm trying to make a Loading View by adding a IsLoading parameter to a custom ContentPage and when set, a View with some Labels and a ActivityIndicator appears on top. Here is the custom page:
public class PageWithLoading : ContentPage, INotifyPropertyChanged
{
private bool isLoading;
public bool IsLoading
{
get
{
return this.isLoading;
}
set
{
this.isLoading = value;
RaisePropertyChanged("IsLoading");
}
}
private string _subtitle;
public string subtitle
{
get
{
return this._subtitle;
}
set
{
this._subtitle = value;
RaisePropertyChanged("subtitle");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
public PageWithLoading()
{
}
public void Loading(bool loading, string text = "")
{
IsLoading = loading;
subtitle = text;
}
}
If I make a Page that inherits from this, and set IsLoading = true, this should appear:
<AbsoluteLayout x:Name="loadingView" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" IsVisible="{Binding IsLoading}">
<ContentView BackgroundColor="#222222" Opacity="0.75" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"/>
<StackLayout BackgroundColor="White" AbsoluteLayout.LayoutBounds=".5,.35,.85,.85" AbsoluteLayout.LayoutFlags="All" VerticalOptions="Center">
<Label Text="Carregando" FontSize="35" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Center" />
<ActivityIndicator IsRunning="true" />
<Label Text="{Binding subtitle}" FontSize="20" VerticalOptions="Center" HorizontalOptions="Center" />
</StackLayout>
</AbsoluteLayout>
And it works if I try to test with something simple, like:
Loading(true, "Logging in");
await Task.Delay(3000);
Loading(false);
but if I try to actually load something (in this case using two task to get some objects from a DynamoDB table) the view doesn't appear, but it seems to be under the rest of the page since you can see a glimpse of it when the page changes