Akash Agrawal
Akash Agrawal

Reputation: 73

Loader image in xamarin.forms?

How to display loader image. If service is hitting, I want to display loader image in background in Xamarin.Forms.

Upvotes: 2

Views: 3869

Answers (4)

Nurhak Kaya
Nurhak Kaya

Reputation: 1781

Use Xamarin.Forms' ActivityIndicator. Click here for details please.

This is how I use it, you just need to create a new property in your view model and call it as IsLoading, if this is set to true, then Activity Indicator will be visible, that is all you need;

// IsLoading property in the viewmodel
  public bool IsLoading
  {
      get
      {
          return isLoading;
      }
      set
      {
          isLoading = value;
          OnPropertyChanged();
      }
  }


//code sample in xaml
  <Grid Grid.Row="1"
  IsVisible="{Binding IsLoading}"
  BackgroundColor="Black"
  Opacity="0.25">
  <Grid.RowDefinitions>
    <RowDefinition Height="1*"/>
    <RowDefinition Height="1*"/>
  </Grid.RowDefinitions>

  <ActivityIndicator  Grid.Row="0"
                      IsVisible="{Binding IsLoading}"
                      IsRunning="{Binding IsLoading}"
                      VerticalOptions="End"
                      HorizontalOptions="Center"/>
  <Label Grid.Row="1"
         Text="Please wait..."
         TextColor="White"
         VerticalOptions="Start"
         HorizontalOptions="Center"/>

</Grid>

Upvotes: 1

Vinit Saxena
Vinit Saxena

Reputation: 704

For implementation of Loader or ActivityIndicator, Xamarin has provided pretty good components for iOS and android. i.e. btprogresshud for iOS and Andhud for Android. These components can be used through Xamarin.Forms.

Upvotes: 0

Falko
Falko

Reputation: 17867

Xamarin.Forms has an ActivityIndicator: http://iosapi.xamarin.com/index.aspx?link=T%3AXamarin.Forms.ActivityIndicator You'll probably find various code examples on how to use it.

If the core problem is how to load something in the background while displaying any "loading" indicator, you might look into this example: http://xforms-kickstarter.com/#asynchronous-web-requests

Upvotes: 3

Falco Winkler
Falco Winkler

Reputation: 1190

Your Question is not very clear,

I guess you just mean you want to notify the user with a loading animation, while a task running in the background is taking some time?

Check http://developer.xamarin.com/recipes/ios/standard_controls/popovers/display_a_loading_message/ for a quick and easy way to implement that. The code there is quite editable so you can adapt it for your needs.

For a cross platform solution (Xamarin.Forms), you might want to look at:

Xamarin Forms show blocking loading message

Upvotes: 0

Related Questions