服务使用Xamarin Forms获取数据时加载图像

时间:2016-07-08 09:32:44

标签: xamarin xamarin.ios xamarin.android xamarin.forms

在登录页面的应用程序中,我想加载带有消息的图像"正在加载"在服务获取数据之前以xamarin形式。 enter image description here

为此,我使用了活动指示符,如下所示:

 ActivityIndicator indicator = new ActivityIndicator { Color = Color.Blue, };
        indicator.IsRunning = false;
       indicator.IsVisible = false;
        indicator.HorizontalOptions = LayoutOptions.CenterAndExpand;
        indicator.VerticalOptions = LayoutOptions.CenterAndExpand;

点击“登录”按钮后,我添加了这样的代码

  indicator.IsRunning = true;
  indicator.IsVisible = true;

现在我只能在同一个屏幕上加载图片。但我想要像上面的图像。任何人都建议我解决这个问题。                                         提前致谢

1 个答案:

答案 0 :(得分:0)

您可以将以下库用于对话框 它支持Xamarin.Forms以及

https://www.nuget.org/packages/Acr.UserDialogs/

编辑1

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Collections.ObjectModel;
    **using Acr.UserDialogs;**
    using Xamarin.Forms;
    using Splat;

    namespace ProjectScreen
    {

        public partial class MainPage : ContentPage
        {
            public ObservableCollection<MainPageViewModel> projects { get; set; }
            public SQLite.Net.SQLiteConnection _connection;
            public bool IsLoading;
            public MainPage()
            {
                projects = new ObservableCollection<MainPageViewModel>();
                InitializeComponent();
                this.getConnection();
                foreach (Project Pname in this.GetProjects())
                {
                    projects.Add(new MainPageViewModel { Name = Pname.name  });
                    lstView.ItemsSource = projects;
                }
                AddNewItem.Clicked += (o, s) =>
                {
                    this.PromptCommand();
                };
                lstView.ItemSelected += LstView_ItemSelected;
            }

            private void LstView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
            { 
                    **UserDialogs.Instance.ShowLoading("Loading data");**
                    Task.Run(() => { waitForMinute(); });
            }

            private async void waitForMinute()
            {
                await Task.Delay(10000);
                **UserDialogs.Instance.Loading().Hide();**
                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PushAsync(new NavigationPage(new ProjectDetails()));
                });
            }
}
}
}

用**表示的行代表AcrDialog您可以根据您的要求在任何文件中使用它们

确保你在主线程上运行它们