在Xamarin.Forms上居中一个Activityindicator
我有上面的代码XAML,我试图在单击Button后将ActivityIndicator放在页面的中心。 我尝试使用网络的例子,但没有成功。
这是代码的开头:
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
插入一个垂直和水平居中的ÀctivityIndicator。
像这样:
这个观点背后的代码:
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
我说应该运行activityIndicator。
在网格中发生的是网格中的所有控件默认采用Grid.Column
和Grid.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; } }
希望能帮助到你。