コード例 #1
0
        private async Task <AccordionMultiViewSource> SetupMealPlanOptionList(MealPlanOptionDetail mealPlanOptionDetail,
                                                                              List <MealPlanOptionListDetail> mealPlanOptionListDetails, string viewType)
        {
            var contentListView = new ListView();
            await Task.Run(() =>
            {
                contentListView = new ListView()
                {
                    // Source of data items.
                    ItemsSource = mealPlanOptionListDetails,
                    Header      = new StackLayout
                    {
                        Orientation       = StackOrientation.Vertical,
                        VerticalOptions   = LayoutOptions.Center,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Margin            = new Thickness(5, 0, 5, 0),
                        Children          =
                        {
                            new Image()
                            {
                                VerticalOptions   = LayoutOptions.Start,
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                                Aspect            = Aspect.AspectFill,
                                Source            = mealPlanOptionDetail.MealOptionPhoto,
                                IsVisible         = mealPlanOptionDetail.MealOptionPhoto != null,
                                Margin            = new Thickness(10, 0, 10, 0)
                            },
                            new Label()
                            {
                                LineBreakMode     = LineBreakMode.TailTruncation,
                                VerticalOptions   = LayoutOptions.Start,
                                HorizontalOptions = LayoutOptions.StartAndExpand,
                                Style             = (Style)App.CurrentApp.Resources["labelAccordionStyleItemTitle"],
                                Text      = mealPlanOptionDetail.MealOptionSubtitle,
                                IsVisible = !string.IsNullOrEmpty(mealPlanOptionDetail.MealOptionSubtitle)
                            },
                            new StackLayout()
                            {
                                HeightRequest     = 1,
                                BackgroundColor   = Palette._TitleTexts,
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                                VerticalOptions   = LayoutOptions.End,
                                IsVisible         = !string.IsNullOrEmpty(mealPlanOptionDetail.MealOptionSubtitle)
                            }
                        }
                    },

                    // Define template for displaying each item. (Argument of DataTemplate
                    // constructor is called for each item; it must return a Cell derivative.)
                    ItemTemplate = new DataTemplate(() =>
                    {
                        // Create views with bindings for displaying each property.
                        Label titleLabel = new Label()
                        {
                            LineBreakMode     = LineBreakMode.WordWrap,
                            VerticalOptions   = LayoutOptions.Center,
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            Style             = (Style)App.CurrentApp.Resources["labelAccordionStyleItem"]
                        };
                        titleLabel.SetBinding(Label.TextProperty,
                                              new Binding("MealOptionDetail", BindingMode.OneWay, null, null, "{0}"));

                        // Return an assembled ViewCell.
                        return(new ViewCell
                        {
                            View = new StackLayout
                            {
                                Orientation = StackOrientation.Vertical,
                                VerticalOptions = LayoutOptions.Center,
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                                Padding = new Thickness(5, 0, 5, 0),
                                Margin = new Thickness(0, 5, 0, 10),
                                Children =
                                {
                                    new StackLayout
                                    {
                                        Orientation = StackOrientation.Horizontal,
                                        VerticalOptions = LayoutOptions.Center,
                                        HorizontalOptions = LayoutOptions.FillAndExpand,
                                        Padding = new Thickness(5, 0, 5, 0),
                                        Children =
                                        {
                                            new StackLayout()
                                            {
                                                VerticalOptions = LayoutOptions.Start,
                                                HorizontalOptions = LayoutOptions.Start,
                                                BackgroundColor = Palette._TitleTexts,
                                                HeightRequest = 4,
                                                WidthRequest = 4,
                                                Margin = new Thickness(0, 8, 0, 0)
                                            },
                                            titleLabel
                                        },
                                    }
                                },
                            },
                        });
                    }),
                    SeparatorVisibility = SeparatorVisibility.None,
                    Margin          = new Thickness(0),
                    VerticalOptions = LayoutOptions.Start,
                    RowHeight       = 70,
                    HasUnevenRows   = true,
                    BackgroundColor = Color.Transparent
                };
                //contentListView.HeightRequest = (contentListView.RowHeight * (mealPlanOptionListDetails.Count)) + 65;
                contentListView.ItemSelected += (sender, e) => contentListView.SelectedItem = null;
            });

            return(new AccordionMultiViewSource()
            {
                HeaderText = mealPlanOptionDetail.MealOptionTitle,
                HeaderStyle = (Style)App.CurrentApp.Resources["buttonStyleGray"],
                HeaderSelectedStyle = (Style)App.CurrentApp.Resources["buttonStyle"],
                ViewType = viewType,
                ContentItems = contentListView
            });
        }
コード例 #2
0
        private async Task <AccordionMultiViewSource> SetupMealPlanOptionGrid(MealPlanOptionDetail mealPlanOptionDetail,
                                                                              List <MealPlanOptionGridDetail> mealPlanOptionGridDetails, string viewType)
        {
            var contentListView = new ListView();
            await Task.Run(() =>
            {
                contentListView = new ListView()
                {
                    // Source of data items.
                    ItemsSource = mealPlanOptionGridDetails,
                    Header      = new StackLayout
                    {
                        VerticalOptions   = LayoutOptions.Center,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Margin            = new Thickness(5, 0, 5, 0),
                        Children          =
                        {
                            new Image()
                            {
                                VerticalOptions   = LayoutOptions.Start,
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                                Aspect            = Aspect.AspectFill,
                                Source            = mealPlanOptionDetail.MealOptionPhoto,
                                IsVisible         = mealPlanOptionDetail.MealOptionPhoto != null
                            },
                            new Label()
                            {
                                LineBreakMode     = LineBreakMode.TailTruncation,
                                VerticalOptions   = LayoutOptions.End,
                                HorizontalOptions = LayoutOptions.StartAndExpand,
                                Style             = (Style)App.CurrentApp.Resources["labelAccordionStyleItemHeader"],
                                Text      = mealPlanOptionDetail.MealOptionSubtitle,
                                IsVisible = !string.IsNullOrEmpty(mealPlanOptionDetail.MealOptionSubtitle)
                            },
                            new StackLayout()
                            {
                                HeightRequest     = 1,
                                BackgroundColor   = Palette._TitleTexts,
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                                VerticalOptions   = LayoutOptions.End,
                                IsVisible         = !string.IsNullOrEmpty(mealPlanOptionDetail.MealOptionSubtitle)
                            }
                        }
                    },

                    // Define template for displaying each item. (Argument of DataTemplate
                    // constructor is called for each item; it must return a Cell derivative.)
                    ItemTemplate = new DataTemplate(() =>
                    {
                        // Create views with bindings for displaying each property.
                        Label mealOptionVolumeLabel = new Label()
                        {
                            Style             = (Style)App.CurrentApp.Resources["labelAccordionStyleItem"],
                            VerticalOptions   = LayoutOptions.Center,
                            HorizontalOptions = LayoutOptions.StartAndExpand
                        };
                        mealOptionVolumeLabel.SetBinding(Label.TextProperty,
                                                         new Binding("MealOptionVolume", BindingMode.OneWay, null, null, "{0}"));

                        Label mealOptionVolumeTypeLabel = new Label()
                        {
                            Style             = (Style)App.CurrentApp.Resources["labelAccordionStyleItem"],
                            VerticalOptions   = LayoutOptions.Center,
                            HorizontalOptions = LayoutOptions.StartAndExpand
                        };
                        mealOptionVolumeTypeLabel.SetBinding(Label.TextProperty,
                                                             new Binding("MealOptionVolumeType", BindingMode.OneWay, null, null, "{0}"));

                        Label titleLabel = new Label()
                        {
                            LineBreakMode     = LineBreakMode.TailTruncation,
                            Style             = (Style)App.CurrentApp.Resources["labelAccordionStyleItem"],
                            VerticalOptions   = LayoutOptions.Center,
                            HorizontalOptions = LayoutOptions.StartAndExpand
                        };
                        titleLabel.SetBinding(Label.TextProperty,
                                              new Binding("MealOptionShakeTitle", BindingMode.OneWay, null, null, "{0}"));

                        var grid = new Grid()
                        {
                            RowDefinitions =
                            {
                                new RowDefinition()
                                {
                                    Height = GridLength.Auto
                                }
                            },
                            ColumnDefinitions =
                            {
                                new ColumnDefinition()
                                {
                                    Width = 25
                                },
                                new ColumnDefinition()
                                {
                                    Width = 50
                                },
                                new ColumnDefinition()
                                {
                                    Width = GridLength.Star
                                }
                            },
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                        };

                        grid.Children.Add(mealOptionVolumeLabel, 0, 0);
                        grid.Children.Add(mealOptionVolumeTypeLabel, 1, 0);
                        grid.Children.Add(titleLabel, 2, 0);

                        // Return an assembled ViewCell.
                        return(new ViewCell
                        {
                            View = new StackLayout
                            {
                                Orientation = StackOrientation.Vertical,
                                VerticalOptions = LayoutOptions.Center,
                                HorizontalOptions = LayoutOptions.FillAndExpand,
                                Padding = new Thickness(5, 0, 0, 0),
                                Margin = new Thickness(0, 5, 0, 10),
                                Children =
                                {
                                    grid
                                },
                            },
                        });
                    }),
                    SeparatorVisibility = SeparatorVisibility.None,
                    Margin          = new Thickness(10, 0, 10, 0),
                    VerticalOptions = LayoutOptions.Start,
                    RowHeight       = 25,
                    HasUnevenRows   = false,
                    BackgroundColor = Color.Transparent
                };

                contentListView.HeightRequest =
                    (contentListView.RowHeight * (mealPlanOptionDetail.MealPlanOptionGridDetails.Count)) + 15;

                contentListView.ItemSelected += (sender, e) => contentListView.SelectedItem = null;
                //contentListView.HeightRequest = Elements.Length * contentListView.RowHeight;
                //listView.HeightRequest = listView.RowHeight * ((Your List that you want to show in ListView).Count + 1);
            });

            return(new AccordionMultiViewSource()
            {
                HeaderText = mealPlanOptionDetail.MealOptionTitle,
                HeaderStyle = (Style)App.CurrentApp.Resources["labelStyleInfoHeading"],
                HeaderSelectedStyle = (Style)App.CurrentApp.Resources["labelStyleInfoHighlight"],

                HeaderImage = TextResources.icon_plus_gray,
                HeaderImageStyle = (Style)App.CurrentApp.Resources["imageExpandPlus"],
                HeaderImageSelected = TextResources.icon_plus,

                ViewType = viewType,
                ContentItems = contentListView
            });
        }