コード例 #1
0
        public ResultsPage(IEnumerable <Package> packages)
        {
            Title = "Search Results";

            NavigationPage.SetHasNavigationBar(this, true);

            var stackLayout = new StackLayout()
            {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            if (Device.OS == TargetPlatform.WinPhone)
            {
                // WinPhone doesn't have the title showing
                stackLayout.Children.Add(new Label {
                    Text = Title, Font = Font.SystemFontOfSize(50)
                });
            }

            var results    = packages.Select(x => new PackageViewModel(x));
            var resultList = new ListView()
            {
                ItemsSource  = results,
                ItemTemplate = new DataTemplate(() =>
                {
                    var itemList = new Label()
                    {
                        Font = Font.SystemFontOfSize(NamedSize.Medium),
                    };
                    itemList.SetBinding(Label.TextProperty, "ShortSummary");

                    return(new ViewCell()
                    {
                        View = new StackLayout()
                        {
                            Padding = new Thickness(5, 5),
                            Orientation = StackOrientation.Vertical,
                            VerticalOptions = LayoutOptions.FillAndExpand,
                            Children =
                            {
                                itemList,
                            },
                        },
                    });
                }),
            };

            resultList.ItemSelected += (sender, e) =>
            {
                var package     = (PackageViewModel)e.SelectedItem;
                var detailsPage = new DetailsPage();
                detailsPage.BindingContext = package;
                Navigation.PushAsync(detailsPage);
            };
            stackLayout.Children.Add(resultList);

            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
            this.Content = stackLayout;
        }
コード例 #2
0
        public ResultsPage(IEnumerable<Package> packages)
        {
            Title = "Search Results";

            NavigationPage.SetHasNavigationBar(this, true);

            var stackLayout = new StackLayout() { VerticalOptions = LayoutOptions.FillAndExpand };

            if (Device.OS == TargetPlatform.WinPhone)
            {
                // WinPhone doesn't have the title showing
                stackLayout.Children.Add(new Label { Text = Title, Font = Font.SystemFontOfSize(50) });
            }

            var results = packages.Select(x => new PackageViewModel(x));
            var resultList = new ListView()
            {
                ItemsSource = results,
                ItemTemplate = new DataTemplate(() =>
                {
                    var itemList = new Label()
                    {
                        Font = Font.SystemFontOfSize(NamedSize.Medium),
                    };
                    itemList.SetBinding(Label.TextProperty, "ShortSummary");

                    return new ViewCell()
                    {
                        View = new StackLayout()
                        {
                            Padding = new Thickness(5, 5),
                            Orientation = StackOrientation.Vertical,
                            VerticalOptions = LayoutOptions.FillAndExpand,
                            Children =
                            {
                                itemList,
                            },
                        },
                    };
                }),
            };
            resultList.ItemSelected += (sender, e) =>
            {
                var package = (PackageViewModel)e.SelectedItem;
                var detailsPage = new DetailsPage();
                detailsPage.BindingContext = package;
                Navigation.PushAsync(detailsPage);
            };
            stackLayout.Children.Add(resultList);

            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
            this.Content = stackLayout;
        }
コード例 #3
0
        public ResultsPage()
        {
            Title = "Search Results";

            NavigationPage.SetHasNavigationBar(this, true);

            var stackLayout = new StackLayout()
            {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            if (Device.OS == TargetPlatform.WinPhone)
            {
                // WinPhone doesn't have the title showing
                stackLayout.Children.Add(new Label {
                    Text = Title, Font = Font.SystemFontOfSize(50)
                });
            }

            var searchButton = new Button()
            {
                Text = "Get Data"
            };

            searchButton.Clicked += async(sender, e) =>
            {
                try
                {
                    activityIndicator.IsVisible = true;
                    packages = await GetPackages();

                    if (packages != null)
                    {
                        SetSource();
                    }
                    activityIndicator.IsVisible = false;
                }
                catch (Exception)
                {
                    await DisplayAlert("Error", "Connect to the internet and try again..!", "OK");

                    activityIndicator.IsVisible = false;
                }
            };

            var grid = new Grid();

            activityIndicator = new ActivityIndicator();
            activityIndicator.HeightRequest     = 100;
            activityIndicator.HorizontalOptions = LayoutOptions.Center;
            activityIndicator.VerticalOptions   = LayoutOptions.Center;
            activityIndicator.IsEnabled         = true;
            activityIndicator.IsRunning         = true;
            activityIndicator.IsVisible         = false;

            dataGrid             = new SfDataGrid();
            dataGrid.ColumnSizer = ColumnSizer.Auto;
            dataGrid.GridTapped += (sender, e) =>
            {
                var package     = (PackageViewModel)e.RowData;
                var detailsPage = new DetailsPage();
                detailsPage.BindingContext = package;
                Navigation.PushAsync(detailsPage);
            };

            grid.Children.Add(activityIndicator);
            grid.Children.Add(dataGrid);
            stackLayout.Children.Add(searchButton);
            stackLayout.Children.Add(grid);

            this.Content = stackLayout;
        }