RefreshView not working in CollectionView

fakhravarifakhravari Member ✭✭✭


Is this true?
Because the data is not displayed at all

Answers

  • fakhravarifakhravari Member ✭✭✭

    private HamePageMultiViewModel Model { get; set; }
    public Page1()
    {
    InitializeComponent();

            BindingContext = Model = new HamePageMultiViewModel();
    
            this.LoadDataCommand = new Command(async () => await this.RefreshData());
        }
    
        public bool IsBusy { get; set; }
    
        protected override void OnAppearing()
        {
            base.OnAppearing();
            IsBusy = true;
        }
    
        public Command LoadDataCommand { get; }
    
    
    
        int Row = 1;
    
        public async Task RefreshData()
        {
            Model.Step1.Clear();
    
            if (Row > 4)
            {
                Row = 1;
            }
    
            Model.Step1.AddRange(await BLL.GetListProductHomePageSelect(Row));
    
            Row += 1;
    
            BindingContext = Model;
        }
    
  • igorkr_10igorkr_10 Member ✭✭✭
    edited January 12
    1. Why do you need ScrollView?
    2. Do you have IsRefreshing property in your ViewModel?
    3. Your BindingContext is HamePageMultiViewModel but Command to load data is in your page. Move Command to ViewModel.
    4. Your IsBusy property is not implement INotifyPropertyChanged. Do it like this:

      bool _isBusy = false;
      public bool IsBusy
      {
      get { return _isBusy; }
      set { SetProperty(ref _isBusy, value); }
      }

    5. And solve what the property you use: IsBusy or IsRefreshing?
  • fakhravarifakhravari Member ✭✭✭
    edited January 12

    hi

        public Home()
        {
            InitializeComponent();
            BindingContext = Model = new HamePageMultiViewModel();
    
            RefreshCommand = new Command(ExecuteRefreshCommand);
        }
    
        public ICommand RefreshCommand { get; }
    
        bool isRefreshing;
        public bool IsRefreshing
        {
            get => isRefreshing;
            set
            {
                isRefreshing = value;
                OnPropertyChanged(nameof(IsRefreshing));
            }
        }
        async void ExecuteRefreshCommand()
        {
            Model.Step1.Clear();
            Model.Step1.AddRange(await BLL.GetListProductHomePageSelect(1));
    
            IsRefreshing = false;
        }
    

    Does not display data
    Even the refresh button

    2) display data = ok
    3) display data = ok

    <!-- // RefreshView (1) RefreshView is display data = ok

    Disable StackLayout display data (1) = ok
    Icon Refresh remains constant and its commands are not executed

  • jezhjezh Member, Xamarin Team Xamurai

    I am confused with the following words,could you please post more details about it?

    Even the refresh button

    2) display data = ok
    3) display data = ok

    <!-- // RefreshView (1) RefreshView is display data = ok

    Disable StackLayout display data (1) = ok
    Icon Refresh remains constant and its commands are not executed

    According to your code, I haven't reproduce this question. In order to help you better, could you please post a basic demo or code snippet (not screenshot) so that we can test on our side?

  • fakhravarifakhravari Member ✭✭✭
    edited January 15

    @jezh said:
    I am confused with the following words,could you please post more details about it?

    Even the refresh button

    2) display data = ok
    3) display data = ok

    <!-- // RefreshView (1) RefreshView is display data = ok

    Disable StackLayout display data (1) = ok
    Icon Refresh remains constant and its commands are not executed

    According to your code, I haven't reproduce this question. In order to help you better, could you please post a basic demo or code snippet (not screenshot) so that we can test on our side?

    hi
    Thanks for checking out
    And problem solve

  • jezhjezh Member, Xamarin Team Xamurai

    Great, you've solved the problem! Congrats, and have a nice day. :)

  • fakhravarifakhravari Member ✭✭✭
    app155 not working refresh :#
  • jezhjezh Member, Xamarin Team Xamurai

    I'm so sorry, I misunderstood this words 'problem solve' :p . I will check it and come back asap.

  • jezhjezh Member, Xamarin Team Xamurai
    edited January 17

    After I reviewed the code of App155, I found that the positon of RefreshView is not right.Just put RefreshView outside of CollectionView.

    You can try to code like this:

      <StackLayout>
               <RefreshView IsRefreshing="{Binding IsRefreshing}" Command="{Binding RefreshCommand}">
    
                                <CollectionView ItemsSource="{Binding items}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" ItemSizingStrategy="MeasureAllItems">
                                <CollectionView.ItemsLayout>
                                    <GridItemsLayout Orientation="Vertical" Span="2" VerticalItemSpacing="5" HorizontalItemSpacing="5" />
                                </CollectionView.ItemsLayout>
    
                                <CollectionView.ItemTemplate>
                                    <DataTemplate>
                                        <Frame BorderColor="#455A64" CornerRadius="2" Padding="2">
    
                                                <ScrollView>
                                                    <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="End" Spacing="5">
    
                                                        <ffimageloading:CachedImage Source="{Binding ImageName}" LoadingPlaceholder="{Binding NameFa}" Aspect="AspectFill" HeightRequest="150" />
                                                        <BoxView Color="Gray" HeightRequest="0.5" HorizontalOptions="FillAndExpand" />
                                                        <Label Text="{Binding NameEn}" FontSize="14" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand"/>
                                                        <Label FontAttributes="Bold" TextColor="#5c5cd6" Text="{Binding TotalPrice, StringFormat='🛒 {0:N0}'}" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"></Label>
    
                                                        <Grid ColumnSpacing="0" RowSpacing="0" HorizontalOptions="FillAndExpand">
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="*" />
                                                                <ColumnDefinition Width="*" />
                                                                <ColumnDefinition Width="*"/>
                                                            </Grid.ColumnDefinitions>
                                                            <Grid.RowDefinitions>
                                                                <RowDefinition />
                                                            </Grid.RowDefinitions>
                                                            <StackLayout HorizontalOptions="FillAndExpand" Grid.Column="0" Grid.Row="0" BackgroundColor="Transparent">
                                                                <Button ImageSource="add_circle" ClassId="Step1" CommandParameter="{Binding IdProduct}" BackgroundColor="Transparent"></Button>
                                                            </StackLayout>
                                                            <StackLayout HorizontalOptions="FillAndExpand" Grid.Column="1" Grid.Row="0" BackgroundColor="Transparent">
                                                                <Entry HorizontalTextAlignment="Center" Text="{Binding TedadBag}" Keyboard="Numeric"></Entry>
                                                            </StackLayout>
                                                            <StackLayout HorizontalOptions="FillAndExpand" Grid.Column="2" Grid.Row="0" BackgroundColor="Transparent">
                                                                <Button ImageSource="remove_circle" ClassId="Step1" CommandParameter="{Binding IdProduct}" BackgroundColor="Transparent"></Button>
                                                            </StackLayout>
                                                        </Grid>
                                                    </StackLayout>
                                                </ScrollView>
    
                                        </Frame>
                                    </DataTemplate>
                                </CollectionView.ItemTemplate>
    
                                <CollectionView.EmptyView>
                                    <Label Text="موردی یافت نشد" HorizontalOptions="Center" />
                                </CollectionView.EmptyView>
    
                                <CollectionView.Header>
                                    <StackLayout></StackLayout>
                                </CollectionView.Header>
    
                            </CollectionView>
    
                </RefreshView>
    
         </StackLayout>
    

    Of course,after that ,you should also modify the code of your ViewModel of BindingContext .

    You can refer to the sample code here:https://github.com/xamarin/xamarin-forms-samples/blob/master/UserInterface/CollectionViewDemos/CollectionViewDemos/Views/PullToRefresh/HorizontalGridPullToRefreshPage.xaml

  • fakhravarifakhravari Member ✭✭✭

    hi
    @jezh

    I checked sample HorizontalGridPullToRefreshPage.xaml

    CarouselView = ok

    CollectionView =Is databinding But not display

  • jezhjezh Member, Xamarin Team Xamurai

    I modified your code, and then it worked well. You can check out the full app in the attachment.

    MyViewModel.cs

     public class MyViewModel: INotifyPropertyChanged
        {
            public List<HomePageViewModel> Step1 { get; private set; } = new List<HomePageViewModel>();
    
            public MyViewModel()
            {
                Task.Run(() => MethosFillStep()).Wait();
            }
    
    
            private async Task<int> MethosFillStep()
            {
                Step1 = await BLL.GetListProductHomePageSelect(1);
    
                return 1;
            }
    
            bool isRefreshing;
            public bool IsRefreshing
            {
                get { return isRefreshing; }
                set
                {
                    isRefreshing = value;
                    OnPropertyChanged();
                }
            }
    
    
            public ICommand RefreshCommand => new Command(async () => await RefreshDataAsync());
    
    
    
            async Task RefreshDataAsync()
            {
                IsRefreshing = true;
    
               // Task.Run(() => MethosFillStep()).Wait();
    
                IsRefreshing = false;
            }
    
    
            #region INotifyPropertyChanged
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            void OnPropertyChanged([CallerMemberName] string propertyName = null)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
    
            #endregion
    
        }
    
  • fakhravarifakhravari Member ✭✭✭

    hi
    Is refresh
    but not show data in CollectionView

    Of course, data is included in the model of refresh

  • jezhjezh Member, Xamarin Team Xamurai

    Have you downed and tested the app I uploaded above. I tested on myside , it just work properly.(show data in CollectionView).

    If you want to update the new data when you pull down the RefreshView, you just need to modify the code in function RefreshDataAsync.

  • fakhravarifakhravari Member ✭✭✭
    edited January 20

    hi
    see photo
    new data when you pull down = apend data

  • jezhjezh Member, Xamarin Team Xamurai

    Have you resolved this question?

Sign In or Register to comment.