Disable Xamarin Form and Show Activity Indicator
Asked Answered
V

2

5

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.

Vendor answered 14/10, 2016 at 13:25 Comment(0)
V
11

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.

Velasquez answered 14/10, 2016 at 13:41 Comment(3)
Thanks for the answer. Will try this.Vendor
This works great! Can you tell me the reason for using a Grid please?Herrod
@Curiousity, Grid is used here (in the upper example with ContentView overlaying ScrollView in z-axis) because ScrollView and ContentView both occupy row 0 as the same-sized region-rectangle. The ContentView is higher in z-axis, but is initially invisible until it is later made visible, eclipsing in front of the ScrollView. No other control makes this both-occupy-the-same-region-rectangle trick work as easily as duplicating the row ID.Stettin
G
1

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>
Gehenna answered 3/2, 2020 at 13:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.