Xamarin - 在执行命令

时间:2016-04-18 02:31:44

标签: android ios xamarin

我正在使用xamarin表单来开发我的项目,现在我正在使用Jason Smith组件来刷新我的视图

https://github.com/jamesmontemagno/Xamarin.Forms-PullToRefreshLayout

但是,我使用以下代码

        scrollControl.RefreshCommand = RefreshCommand;
        public ICommand RefreshCommand
        {
            get {return new Command(async () => await ContentScrollView_Scrolled()); }
        }
        async Task ContentScrollView_Scrolled()
        {
......
        }

在我执行所有代码之后,刷新图标仍然在那里旋转,我试图在命令的最后放置scrollControl.isRefreshing = false,但是不起作用,任何人都可以帮我这个?

2 个答案:

答案 0 :(得分:0)

我怀疑当你的刷新完成后你没有更新UI线程上的IsRefreshing属性。试试这个:

// after your refresh command completes
Device.BeginInvokeOnMainThread (() => {
  scrollControl.IsRefreshing = false;
});

答案 1 :(得分:0)

好吧,这个解决方案有点奇怪,我发现它,因为isrefreshing属性是假的,所以我在代码的开头将isrefreshing设置为true,我认为它会自动设置为true所以我必须手动我自己,最终它像魅力一样工作

 scrollControl.RefreshCommand = RefreshCommand;
        public ICommand RefreshCommand
        {
            get {return new Command(async () => await ContentScrollView_Scrolled()); }
        }
        async Task ContentScrollView_Scrolled()
        {
        scrollControl.isRefreshing = true;
......
        scrollControl.isRefreshing = false;
        }