Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ListView is pull to refresh really right?

$
0
0

Hello Guys,

I implemented a listView with is pull to refresh... but Im not really sure if it is right.
In the example I followed I should bind the IsPullToRefreshEnabled to a bool, but since Im not pretty sure about binding context I didnt use it...
My code works but is it really right?

public class TestPage : ContentPage
    {
        private bool isBusy;

        public bool IsBusy {
            get { return isBusy; }
            set {
                if (isBusy == value)
                    return; isBusy = value;
                OnPropertyChanged ("IsBusy");
            }
        }

        private Command loadTestCommand;
        public Command LoadTestCommand {
            get {
                return loadTestCommand ?? (loadTestCommand = new Command (ExecuteLoadTestCommand, ()=> { return !IsBusy; }));
            }
        }
        private async void ExecuteLoadTestCommand () {
            if (IsBusy) return;
            IsBusy = true;
            LoadTestCommand.ChangeCanExecute();
            //DoStuff
            listView.ItemsSource = GetTestList();  //function that gets a new list

            IsBusy = false;
            LoadTestCommand.ChangeCanExecute();
            listView.EndRefresh ();
        }

        List<Model_Test_ListView>testList  = new List<Model_Test_ListView>();


        ListView listView;

        public TestPage ()
        {



            testList = GetTestList();

            listView = new ListView
            {
                IsPullToRefreshEnabled = true,
                RefreshCommand = LoadTestCommand,
                IsRefreshing = IsBusy, //here not sure if it is right
            };


            listView.ItemsSource = testList;


            Content = listView;


        }

Anyone could say if it is right?
Also anyone knows a good tuto about binding context and commands? I still have some doubts about it...

Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>