Xamarin Forms CarouselPage ActivityIndicator в каждом ContentPages не работает - PullRequest
0 голосов
/ 31 октября 2018

У меня есть CarouselPage, в котором у меня есть около 6 страниц контента Каждая страница имеет ListView для списка выбора. Когда ListItem выбран (постучал), пользователь переходит на следующую ContentPage с соответствующими критериями на основе предыдущего выбора. Все работает гладко. Но иногда это требует времени на определенных страницах. Я хочу отобразить ActivityIndicator для пользователя, чтобы он не чувствовал, что он не нажал, или он пытается двойное нажатие или любые другие проблемы с ожиданием.

То, что я работал: -

Это информация заголовка запуска CarouselPage

<CarouselPage x:Name="CarouselPage_Selection_Page"
              xmlns="http://xamarin.com/schemas/2014/forms"  
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
              xmlns:local="clr-namespace:saralEHR"
              Padding="0"
              Title="Selection Pages">

Ниже приведен код XAML: -

   <ContentPage Padding="5"
        x:Name="ContentPage_Select_Visiting_Location">
        <Grid BackgroundColor="Transparent" RowSpacing="0" Margin="10" Padding="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="3*" />
                <RowDefinition Height="108"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <StackLayout Grid.Row="0" VerticalOptions="Start" HorizontalOptions="FillAndExpand" BackgroundColor="Black">
                <Label Text="SELECT LOCATION" BackgroundColor="Black" TextColor="White"/>
            </StackLayout>
            <StackLayout Grid.Row="1" VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" BackgroundColor="Transparent">
                <ListView x:Name="ListView_Visiting_Location_Name"
                            ItemsSource="{Binding Visiting_Location_Name_Table}" 
                            ItemTapped="ListView_Visiting_Location_Name_ItemTapped">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">
                                    <Label x:Name="Label_Visiting_Location_Name"
                                            Text="{Binding Visiting_Location_Name}"
                                            FontAttributes="Bold">
                                    </Label>
                                    <Label x:Name="Label_Visiting_Location_ID"
                                            Text="{Binding Visiting_Location_ID, StringFormat='{0:F0}'}"
                                            IsVisible="False">
                                    </Label>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
                <ActivityIndicator 
                        x:Name="ActivityIndicator_Busy_Selected_Visiting_Location"
                        Color="Black"
                        IsEnabled="True" 
                        HorizontalOptions="Center" 
                        VerticalOptions="Center"
                        IsRunning="{Binding Source={x:Reference ContentPage_Select_Visiting_Location}, Path=IsBusy}" 
                        IsVisible="{Binding Source={x:Reference ContentPage_Select_Visiting_Location}, Path=IsBusy}" />
            </StackLayout>
        </Grid>
    </ContentPage>

И, наконец, это код xaml.cs, стоящий за файлом: -

protected async void ListView_Visiting_Location_Name_ItemTapped(object sender, ItemTappedEventArgs e)
{
    string where_clause = "";

    ContentPage_Select_Visiting_Location.IsBusy = true;

    await Task.Run(() =>
    {
        Device.BeginInvokeOnMainThread(async () =>
        {
            try
            {
                Sql_Common.selected_appointments_booking_Visiting_Location_ID = (e.Item as Visiting_Location_Master).Visiting_Location_ID;
                Sql_Common.selected_appointments_booking_Visiting_Location_name = (e.Item as Visiting_Location_Master).Visiting_Location_Name;

                ActivityIndicator_Busy_Selected_Visiting_Location.IsRunning = true;
                ActivityIndicator_Busy_Selected_Visiting_Location.IsVisible = true;

                await Task.Delay(3000);

                Load_Slot_Date_Details();

            }
            catch (Exception ex)
            {
                await DisplayAlert("Error!", ex.Message + where_clause, "Ok");
            }

            int index = Children.IndexOf(CurrentPage);
            this.CurrentPage = this.Children[index + 1];

            ActivityIndicator_Busy_Selected_Visiting_Location.IsRunning = false;

            this.IsBusy = false;

        });

    });

    ActivityIndicator_Busy_Selected_Visiting_Location.IsRunning = false;

    this.IsBusy = false;

    ContentPage_Select_Visiting_Location.IsBusy = false;
}

Вы можете обнаружить, что я провел много тренировок, подобных этой.IsBusy = true, ActivityIndicator_Busy_Selected_Visiting_Location.IsRunning = true; и т.д. но ничего не работает.

Любая помощь в отношении того же была бы весьма ценной.

У меня в Google много тем, но ничего не найдено, в частности, работает ActivityIndicator в отдельном ContentPage в CarouselPage, который имеет несколько ContentPage

1 Ответ

0 голосов
/ 03 ноября 2018

В соответствии с запросом OP, я делаю свой комментарий ответом.

Похоже, что ваш ActivityIndicator вложен в StackLayout. Переместите его наружу, чтобы он стал потомком Grid

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...