Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How To Show A Loading Screen (Cross Platform)

BerkayAKINBerkayAKIN TRMember ✭✭

Hi everyone! I want to show a loading overlay screen on my app till my function gets completed. I want to solve this in a cross platform way. Not with iOS specific or Android specific code. Thanks!

Best Answer

Answers

  • AndrewMobileAndrewMobile USMember ✭✭✭✭
    Accepted Answer

    Xamarin Forms has a control called ActivityIndicator
    http://iosapi.xamarin.com/index.aspx?link=T:Xamarin.Forms.ActivityIndicator

    This works if you don't have a requirement for a specific look, otherwise it should be pretty easy to make your own.

  • BerkayAKINBerkayAKIN TRMember ✭✭

    thank you very much!

  • KirlyJzsefKirlyJzsef USMember

    You can use MVVM and the ViewModel's IsLoading property to bind an otherwise invisible Grid and ActivityIndicator over the content (by putting your whole page's content into a Grid, with the content being the first item, and the overlay being the second. Something like this:

    <ContentPage>
        <Grid>
            <StackLayout x:Name="Your content" />
            <Grid x:Name="loadingOverlay" IsVisible="{Binding IsLoading}">
                <ActivityIndicator IsRunning="{Binding IsLoading}" />
            </Grid>
        </Grid>
    </ContentPage>
    
  • BerkayAKINBerkayAKIN TRMember ✭✭

    Cant put grid in contentpage or stacklayout. I get error. I try to use it in CS file.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Take a look at this example.

  • PavanParekhPavanParekh USMember ✭✭

    @AlessandroCaliaro , I am using UserDialogs and facing issue: "at Microsoft.Phone.Controls.CustomMessageBox.ClosePopup(Boolean restoreOriginalValues)" at App.xaml.cs page in Windows project.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @Pavan7Parekh you should ask to @AllanRitchie

  • SurbhiAroraSurbhiArora USMember ✭✭

    I want to add progress bar till the function gets completed.. and where to add the code of activity indicator and if we need to make a new xcml page then how to set it as launch screen?

  • SujaBSujaB USUniversity ✭✭✭
    edited December 2016

    @AllanRitchie
    Hi

    Iam developing an ipad application in xamarin.forms.I installed acr.user dialogs versions 4.1.0,4.2.1,4.3.4 .

    But while running the application iam getting object reference not set to an instance of an object error.

    Is there any other thing i should give?

     FreshIOC.Container.Register<IUserDialogs>(UserDialogs.Instance); Given this also
    
  • NMackayNMackay GBInsider, University admin

    @SujaB

    Have you initialised in Android before trying to register in the IoC?

    Try adding UserDialogs.Init(this); to your MainActivity and try again.

    https://github.com/aritchie/userdialogs

  • SujaBSujaB USUniversity ✭✭✭

    @NMackay

    But iam using only IOS application.Then also i need to edit in android?

  • NMackayNMackay GBInsider, University admin

    @SujaB

    Sorry, missed the iPad bit. The error does hint the library hasn't been instantiated although apparently you don't need to that anymore for iOS and Windows.

    I'll step out of this one, Allan will be able to assist you.

  • SujaBSujaB USUniversity ✭✭✭

    @NMackay @AllanRitchie

    Thank you so much.I was planning to use Activityindicator. Since Acr.Userdialogs has so many extra features i wanted to use that in my application

    I need to add one more point.I have installed xamarin .forms 2.0.0.6490 version

  • SujaBSujaB USUniversity ✭✭✭

    @NMackay @AllanRitchie

    Hi
    Some progress i have found.When i give this inside a command it is working fine.When i give this inside init function it is showing error.

  • NMackayNMackay GBInsider, University admin
    edited December 2016

    @SujaB

    That's a pretty old version of Forms. You'll have to be careful which version of the plugin your using. I'm guessing your registering it in the IoC as you want to inject the interface into your viewmodels

  • SujaBSujaB USUniversity ✭✭✭

    @NMackay
    Sorry i didnot get your point.It will be because of xamarin.forms version?

  • NMackayNMackay GBInsider, University admin

    @SujaB

    I'm guessing your using the latest version of AcrDialog, I'm just suggesting as your using an old version of Forms that you check that AcrDialog 6.3.2 is compatible fully with Forms 2.0.0, for example your Android project would fail as they have different dependencies to GooglePlayServices.

  • NMackayNMackay GBInsider, University admin

    Maybe try adding UserDialogs.Init(this); to your main activity anyway.

    I can't assist any further.

  • SujaBSujaB USUniversity ✭✭✭

    @NMackay
    Iam using Acr.userdialogs version 4.2.1 and xamarin.forms version 2.0.0.6490

  • AllanRitchieAllanRitchie CAInsider, University ✭✭✭

    @SujaB update your version and look at the FAQ section on the github.com/aritchie/userdialogs

  • Sushil_KumarSushil_Kumar Member ✭✭

    @AlessandroCaliaro said:
    I suggest you to use @AllanRitchie UserDialogs plugin. It has a "ShowLoading" method

    UserDialogs.Instance.ShowLoading("Attendi...");

    Hi sir,

    User Dialog not showing in center in iOS6 and iOS6+, what do for this,It's worked well for Android.

    Thanks.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I suggest to open an issue on github repo

  • DevabakthiniDevabakthini INMember ✭✭

    HI guys
    In Android by using ACR.User Dialogs loaders are aligned vertically center but when it comes to iOS loaders are not coming center(coming at top).Can anyone help me to resolve this?
    Thank You
    Can you have any solution
    For me also same issue

    Thanks In Advance

Sign In or Register to comment.