在Xamarin.Forms上居中一个Activityindicator

我有上面的代码XAML,我试图在单击Button后将ActivityIndi​​cator放在页面的中心。 我尝试使用网络的例子,但没有成功。

   

这是代码的开头:

 public partial class LoginPage : ContentPage { public LoginPage() { IsBusy = false; InitializeComponent(); int contadorErroLogin = 0; string result = null; BtnLogin.Clicked += async (sender, e) => { IsBusy = true; 

当启动IsBusy = false但屏幕似乎是真的。

试试这个:

                      

您可以尝试将ScrollViewer封装在Grid并在ScrollViewer插入一个垂直和水平居中的ÀctivityIndi​​cator。

像这样:

                 

这个观点背后的代码:

 public MainPage() { this.InitializeComponent(); this.BtnLogin.Clicked += BtnLogin_Clicked; } private void BtnLogin_Clicked(object sender, EventArgs e) { this.activityIndicator.IsRunning = true; // TODO: do stuff here } 

当我点击BtnLogin我说应该运行activityIndi​​cator。

在网格中发生的是网格中的所有控件默认采用Grid.ColumnGrid.Row 0。 所以所有控件都是另一个。

编辑:

如果您尝试使用MVVM方法,则可以定义当前视图具有BindingContext

视图:

                   

代码背后:

 public partial class MainPage : ContentPage { public MainPage() { this.InitializeComponent(); // Define the binding context this.BindingContext = this; // Set the IsBusy property this.IsBusy = false; // Login button action this.BtnLogin.Clicked += BtnLogin_Clicked; } private void BtnLogin_Clicked(object sender, EventArgs e) { this.IsBusy = true; } } 

希望能帮助到你。