I'm developing a Xamarin Forms application. I want to show an ActivityIndicator while getting data & binding it to a ListView control from web API. In my code, ActivityIndicator doesn't show at all. I'm using Visual Studio 2017 with Xamarin 4.10.
Following is my code.
Code Behind
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TestPage : ContentPage
{
private SfListView listView;
private ActivityIndicator activityIndicator;
public TestPage()
{
InitializeComponent();
StackLayout mainStackLayout = new StackLayout();
activityIndicator = new ActivityIndicator()
{
IsRunning = true,
IsEnabled = true,
IsVisible = true
};
listView = new SfListView()
{
SelectionMode = SelectionMode.None,
BackgroundColor = Color.White
};
mainStackLayout.Children.Add(activityIndicator);
mainStackLayout.Children.Add(listView);
this.Content = mainStackLayout;
this.Title = "Dashboard";
}
protected override void OnAppearing()
{
SummaryRepository viewModel = new SummaryRepository();
listView.ItemsSource = viewModel.Summary;
listView.ItemTemplate = new DataTemplate(() =>
{
var grid = new Grid();
var bookName = new Label
{
BackgroundColor = Color.White,
FontSize = 16,
TextColor = Color.FromHex("#1A237E")
};
var bookDescription = new Label
{
BackgroundColor = Color.White,
FontSize = 16,
HorizontalTextAlignment = TextAlignment.End,
TextColor = Color.FromHex("#EC407A")
};
bookName.SetBinding(Label.TextProperty, new Binding("Name"));
bookDescription.SetBinding(Label.TextProperty, new Binding("Amount"));
grid.Children.Add(bookName);
grid.Children.Add(bookDescription, 1, 0);
return grid;
});
activityIndicator.IsRunning = false;
base.OnAppearing();
}
}
XAML File
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="eWallet.Pages.TestPage">
<ContentPage.Content>
<StackLayout>
</StackLayout>
</ContentPage.Content>
Any help is highly appreciated.