我正在开发一个 xamarin 表单应用程序,我想添加以显示“正在加载”状态。但我现在就面临这个问题。当我打开该页面时,会显示底部堆栈布局,但它永远不会改变任何内容,并且不会显示我的主页。
XAML:
ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:İdaServis.ViewModels"
x:Class="İdaServis.View.SamplePage">
<ContentPage.BindingContext>
<local:SamplePageViewModel/>
</ContentPage.BindingContext>
<ContentPage.Content >
<StackLayout >
<Label Text="Sample Page"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
<StackLayout IsVisible="{Binding Isloading}" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" >
<Label Text="Yükleniyor..." TextColor="Black" FontSize="Medium" />
<ActivityIndicator Color="SpringGreen" IsRunning="True" />
</StackLayout>
我这样写viewodel:
public class SamplePageViewModel : INotifyPropertyChanged
{
private bool _isloading, showPage;
public SamplePageViewModel ()
{
_isloading = true;
showPage = false;
manageLoadings();
}
private async void manageLoadings()
{
await Task.Delay(2500);
_isloading = false;
showPage = true;
OnPropertyChanged();
}
public bool Isloading { get => _isloading; set { _isloading = value; OnPropertyChanged(); } }
public bool ShowPage { get => showPage; set { showPage = value; OnPropertyChanged(); } }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
我认为这与 IsRunning 属性有关
<ActivityIndicator IsRunning="true" />
另请查看文档 https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/activityindicator