活动指示器不会更改可见属性并显示整个页面

问题描述 投票:0回答:1

我正在开发一个 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));
    }
}
c# android xamarin.forms loading
1个回答
0
投票

我认为这与 IsRunning 属性有关

<ActivityIndicator IsRunning="true" />

另请查看文档 https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/activityindicator

© www.soinside.com 2019 - 2024. All rights reserved.