【问题标题】:Loading Image while service gets data using Xamarin Forms在服务使用 Xamarin Forms 获取数据时加载图像
【发布时间】:2016-07-19 08:44:16
【问题描述】:

在我的登录页面应用程序中,我想在服务获取数据之前在 xamarin 表单中加载带有消息“正在加载”的图像。

为此,我使用了这样的活动指示器:

 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;

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

【问题讨论】:

  • 您可以将 ActivityIndi​​cator 和 Image 放在同一个位置,并让 Image 不可见,直到您准备好显示所有内容。然后在使 Image 可见时,使 ActivityIndi​​cator 和 Label 不可见。
  • 它们是放在网格中还是?

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


【解决方案1】:

您可以将以下库用于对话框 它也支持 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 您可以根据需要在任何文件中使用它们

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

【讨论】:

  • 感谢您的回复。我尝试使用 Acr.UserDialogs 包,但出现错误。请指导我如何使用该包在 xamarin 表单中加载消息
  • 非常感谢。现在它正在工作。非常感谢您的支持
  • 以上代码在 ios 中运行良好,但在 android 中无法运行,甚至我在主要活动中添加了这一行 UserDialogs.Init(this);
猜你喜欢
  • 2021-02-24
  • 1970-01-01
  • 2016-05-13
  • 1970-01-01
  • 2017-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-13
相关资源
最近更新 更多