static void OnShowingPropertyChanging(BindableObject bindable, bool oldValue, bool newValue)
 {
     Device.BeginInvokeOnMainThread(delegate {
         ActivityMessageView mv = (ActivityMessageView)bindable;
         mv.indicator.IsRunning = newValue;
         mv.IsVisible           = newValue;
     });
 }
Esempio n. 2
0
        protected IncrementalSearchPage()
        {
            RowsBeforeTheEndToLoad = 10;
            LastSearch             = String.Empty;
            DataLocation           = DataLoadLocation.None;
            AllItems = new ObservableCollection <T>();

            SearchBar = new SearchBar {
                Placeholder = "Search for..."
            };
            SearchBar.SearchButtonPressed += async(sender, args) => await LoadItemsAsync(SearchBar.Text);

            ActivityView = new ActivityMessageView {
                IsVisible = false
            };

            ActivityView.SetBinding(ActivityMessageView.IsShowingProperty,
                                    new Binding("IsBusy", source: this));

            OfflineIndicator = new FramedLabel {
                IsVisible = false,
                Text      = "Currently offline - using cached data"
            };

            this.ListView = new ListView(ListViewCachingStrategy.RecycleElement)
            {
                ItemsSource  = AllItems,
                ItemTemplate = new DataTemplate(typeof(TextCell))
            };

            this.ListView.ItemTapped += async(s, e) => {
                var item = e.Item as T;
                this.ListView.SelectedItem = null;
                await ItemSelectedAsync(item);
            };

            // Provide Access for infinite scrolling by loading more data
            // when you are at the last record
            this.ListView.ItemAppearing += async(sender, e) => {
                if (HasMoreData && !IsLoading)
                {
                    var foundIndex = AllItems.IndexOf(e.Item as T);
                    if (foundIndex == AllItems.Count - RowsBeforeTheEndToLoad)
                    {
                        await LoadNextPageAsync();
                    }
                }
            };

            this.ListView.IsPullToRefreshEnabled = true;
            this.ListView.Refreshing            += async(sender, e) => {
                await LoadItemsAsync(LastSearch);

                this.ListView.IsRefreshing = false;
            };

            var layout = new RelativeLayout();

            layout.Children.Add(
                SearchBar,
                Constraint.Constant(0),
                Constraint.Constant(0),
                Constraint.RelativeToParent(p => p.Width),
                Constraint.Constant(50)
                );

            layout.Children.Add(
                this.ListView,
                Constraint.Constant(0),
                Constraint.Constant(50),
                Constraint.RelativeToParent(p => p.Width),
                Constraint.RelativeToParent(p => p.Height - 50)
                );

            layout.Children.Add(
                OfflineIndicator,
                Constraint.Constant(0),
                Constraint.RelativeToParent(p => p.Height - 45),
                Constraint.RelativeToParent(p => p.Width),
                Constraint.Constant(45)
                );

            layout.Children.Add(
                ActivityView,
                Constraint.RelativeToParent(p => p.Width - 100),
                Constraint.RelativeToParent(p => p.Height - 100),
                Constraint.Constant(90),
                Constraint.Constant(90)
                );

            Content = layout;
        }