How can I display an activity indicator without using asynchronous code?

Alejandro Vargas 0 Reputation points
2025-04-16T21:52:20.7033333+00:00

Example:

Xaml:

            <Frame x:Name="miFrame1"

                BackgroundColor="Gray"

                IsVisible="False"

                Opacity="0.8"

                Padding="0"

                HorizontalOptions="CenterAndExpand"

                VerticalOptions="StartAndExpand">

                <ActivityIndicator x:Name="miActivityIndicator1"

                    BackgroundColor="Black"

                    Color="#808080"

                    IsVisible="True"

                    IsRunning="True"                        

                    HorizontalOptions="CenterAndExpand"

                    VerticalOptions="CenterAndExpand"

                    WidthRequest="35"

                    HeightRequest="35" />

            </Frame>

Xaml.cs

    private void Button_Clicked7(object sender, EventArgs e)

    {

        try

        {

            this.lblError.Text = string.Empty;

            this.miFrame1.IsVisible = true;

            Thread.Sleep(5000);

            DisplayAlert("Alert", "The process is complete.", "OK");

        }

        catch (Exception ex) { this.ShowError(ex.ToString()); }

        finally { this.miFrame1.IsVisible = false; }

    }
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
851 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.