shuhelohelo’s blog

Xamarin.Forms多めです.

RefreshViewの使い方

devblogs.microsoft.com

RefreshViewとはディスプレイを下にぐいっと引っ張ったときに更新処理が行われるおなじみのあれです.

おなじみのアレ↓ f:id:shuhelohelo:20191201023615p:plain

この更新中のぐるぐるを表示させるには,更新をかけたいUIコントロールRefreshViewで囲むだけです.

このぐるぐるの表示を制御するのはIsRefreshingプロパティで,ぐいっと引っ張ったときにこれがTrueになり,ぐるぐる回り始めます.

実際の更新処理ですが,これをCommandを使って実行します.

        public MainPage()
        {
            InitializeComponent();

            //コマンドを登録
            RefreshCommand = new Command(ExecuteRefreshCommand);

            People = GeneratePeople();

            this.BindingContext = this;
        }

        //Commandにわたす更新時の処理を行うメソッド
        private void ExecuteRefreshCommand(object obj)
        {
            People.Clear();
            People = GeneratePeople(DateTime.Now.ToString());

            //ぐるぐるを非表示にする
            IsRefreshing = false;
        }