示例#1
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            this.OneWayBind(ViewModel, vm => vm.Articles, v => v.Articles.ItemsSource).DisposeWith(_bindingsDisposable);
            this.BindCommand(ViewModel, vm => vm.LoadArticles, v => v.Articles, nameof(ListView.Refreshing)).DisposeWith(_bindingsDisposable);

            Articles.Events().ItemSelected.Subscribe(e => ViewModel.SelectArticle.Execute((Article)e.SelectedItem)).DisposeWith(_bindingsDisposable);

            ViewModel.LoadArticles.Subscribe(_ => Articles.EndRefresh());

            this.WhenAnyValue(x => x.ViewModel.LoadArticles)
            .SelectMany(x => x.Execute())
            .Subscribe();

            this.ViewModel.ShowError.RegisterHandler(async interaction => {
                await DisplayAlert("Error", interaction.Input, "Cancel");
                Articles.EndRefresh();
                interaction.SetOutput(Unit.Default);
            });
        }