Beispiel #1
0
        private void OnAccordionMultiViewContentButtonClicked(AccordionMultiViewContentButton sender)
        {
            var senderButton = sender;

            if (!senderButton.Expand)
            {
                foreach (var childItem in mainLayout.Children)
                {
                    if (childItem.GetType() == typeof(ContentView))
                    {
                        childItem.IsVisible = false;
                    }
                    if (childItem.GetType() == typeof(AccordionMultiViewContentButton))
                    {
                        var button = (AccordionMultiViewContentButton)childItem;
                        button.Expand = false;
                    }
                }

                if (senderButton.Expand)
                {
                    senderButton.Expand = false;
                }
                else
                {
                    senderButton.Expand = true;
                }

                senderButton.AssosiatedContent.IsVisible = senderButton.Expand;
            }
        }
Beispiel #2
0
        public void DataBind()
        {
            mainLayout = new StackLayout();
            var layout = new StackLayout();
            var first  = true;

            if (DataSource != null)
            {
                foreach (var singleItem in DataSource)
                {
                    var accordionContent = new ContentView();
                    switch (singleItem?.ViewType)
                    {
                    case "list":

                        var headerButton = new AccordionMultiViewButton()
                        {
                            Text                = singleItem.HeaderText,
                            ButtonStyle         = singleItem.HeaderStyle,
                            ButtonDefaultStyle  = singleItem.HeaderStyle,
                            ButtonSelectedStyle = singleItem.HeaderSelectedStyle
                        };

                        accordionContent = new ContentView()
                        {
                            Content   = singleItem.ContentItems,
                            IsVisible = false
                        };

                        if (first)
                        {
                            headerButton.Expand        = firstExpaned;
                            accordionContent.IsVisible = firstExpaned;
                            first = false;
                        }

                        headerButton.AssosiatedContent = accordionContent;
                        headerButton.Clicked          += OnAccordionMultiViewButtonClicked;
                        layout.Children.Add(headerButton);
                        layout.Children.Add(accordionContent);

                        break;

                    case "grid":

                        var headerContentButton = new AccordionMultiViewContentButton()
                        {
                            Text              = singleItem.HeaderText,
                            TextStyle         = singleItem.HeaderStyle,
                            TextDefaultStyle  = singleItem.HeaderStyle,
                            TextSelectedStyle = singleItem.HeaderSelectedStyle,

                            ImageSource         = singleItem.HeaderImage,
                            ImageDefaultSource  = singleItem.HeaderImage,
                            ImageSelectedSource = singleItem.HeaderImageSelected,
                            ImageStyle          = singleItem.HeaderImageStyle,
                        };

                        accordionContent = new ContentView()
                        {
                            Content   = singleItem.ContentItems,
                            IsVisible = false
                        };

                        if (first)
                        {
                            headerContentButton.Expand = firstExpaned;
                            accordionContent.IsVisible = firstExpaned;
                            first = false;
                        }

                        headerContentButton.AssosiatedContent = accordionContent;
                        headerContentButton.GestureRecognizers.Add(new TapGestureRecognizer()
                        {
                            Command = new Command(() =>
                            {
                                OnAccordionMultiViewContentButtonClicked(headerContentButton);
                            })
                        });

                        layout.Children.Add(headerContentButton);
                        layout.Children.Add(accordionContent);

                        break;
                    }
                }
            }

            mainLayout = layout;
            Content    = mainLayout;
        }