Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Xamarin Form and Show Activity Indicator

I have a Xamarin Form which is using Scroll View. I am trying to show a Activity Indicator at the top as I have a ListView in the middle. But when the user scrolls down the loading is not shown. So, I need help in disabling the page and showing loading at some z-index as in a popup.

like image 293
Rakesh Androtula Avatar asked Oct 14 '16 13:10

Rakesh Androtula


People also ask

What is activityindicator in Xamarin forms?

Xamarin.Forms ActivityIndicator. The Xamarin.Forms ActivityIndicator control displays an animation to show that the application is engaged in a lengthy activity. Unlike the ProgressBar, the ActivityIndicator gives no indication of progress. The ActivityIndicator inherits from View.

How to get the activity indicator to show if the page is running?

In your view model, add a boolean property to indicate if the page is loading. Implement INotifyPropertyChanged in the model and fire PropertyChanged event when you change the property (at setter code). Bind the "IsRunning" property of your activity indicator to the property you added in the first step.

How do I Turn on/off the activity indicator?

After a few seconds, you will see your app working. Click the "Run" Button and run the activity indicator. Click the "Stop" Button to stop the activity indicator. The result is displayed.

How to create an activity indicator in absolutelayout and stacklayout?

We are creating an activity indicator in AbsoluteLayout and a button inside the StackLayout. Two buttons are created -- one button in "Run" and the second button in "Stop". Open Solution Explorer >> Project Name (Portable) >> MainPage.xaml.cs. Open the design view of this page.


2 Answers

If you want to have an overlay while the screen is loading you can do this.

<Grid>

    <ScrollView>
       <!-- Insert your page content in here -->
    </ScrollView>

    <ContentView IsVisible="false" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
         <ActivityIndicator IsRunning="false" />
    </ContentView>

</Grid>

When you set your ContentView to IsVisible="true" it will then overlay on top of your page. You can set the background color and opacity on the ContentView if needed to provide a grey out effect.

Or you can use a similar method and have

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <ActivityIndicator Grid.Row="0" />

    <ScrollView Grid.Row="1">

    </ScrollView>
</Grid>

In this way you will have the activity indicator above the scroll view at all times and allow the user to still scroll.

like image 176
Adam Avatar answered Oct 09 '22 02:10

Adam


I am new to the Xamarin but you do as below.

 <Grid IsEnabled="{Binding IsBusy,Converter={converters:InverseBoolConverter}}"   >
...
     <ActivityIndicator      
              Color="{StaticResource LightGreenColor}"
              IsRunning="{Binding IsBusy}"
              IsVisible="{Binding IsBusy}"
              VerticalOptions="Center"
              HorizontalOptions="Center">
                <ActivityIndicator.WidthRequest>
                    <OnPlatform x:TypeArguments="x:Double">
                        <On Platform="iOS, Android" Value="100" />
                        <On Platform="UWP, WinRT, WinPhone" Value="400" />
                    </OnPlatform>
                </ActivityIndicator.WidthRequest>
            </ActivityIndicator>
        </Grid>
like image 20
Sameer Z. Avatar answered Oct 09 '22 03:10

Sameer Z.