Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Show and Hide Stacklayout using button on clicked

I have a dynamic control where being created when the page is loaded, however, I wanted to include a button also wherein it has a capability to show and hide the stack layout whenever I click it, but I’m not sure how to implement it correctly, please see my code.

                StackLayout commentStack = new();

            var button = new Button();
            button.Text = "+ Add a Comment";
            button.WidthRequest = 100;
            button.Clicked += (sender, e) => OnButtonClicked(commentStack);

            var stackGrid = new Grid()
            {
                RowDefinitions = new()
                {
                    new RowDefinition() { Height = new GridLength(2, GridUnitType.Auto) },
                    new RowDefinition() { Height = new GridLength(2, GridUnitType.Auto) },
                    new RowDefinition() { Height = new GridLength(2, GridUnitType.Auto) },
                },
                ColumnDefinitions = new()
                {
                    new ColumnDefinition(),
                }
            };

            var commentlabel = new Label();
            commentlabel.Text = Translator.Section_Comments;
            commentlabel.FontSize = 17;
            commentlabel.FontAttributes = FontAttributes.Bold;

            var frame = new Frame();
            var editor = new Editor();

            frame.BorderColor = Color.LightGray;
            frame.Padding = 1;
            frame.HasShadow = false;

            editor.IsEnabled = !this.IsReadOnly;
            editor.FontSize = 17;
            editor.HeightRequest = 150;

            editor.TextChanged += (sender, e) => OnEditorCommentTextChanged(question, editor.Text);

            frame.Content = editor;
            stackGrid.Margin = new Thickness(0, 20, 0, 0);

            stackGrid.Children.Add(button);
            stackGrid.Children.Add(commentlabel, 0, 1);
            stackGrid.Children.Add(frame, 0, 2);
            commentStack.Children.Add(stackGrid);

            stack.Children.Add(commentStack);
            this.Children.Add(stack);


        private void OnButtonClicked(StackLayout stack)
    {
        
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use the IsVisible property

stackGrid.IsVisible = !stackGrid.IsVisible;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading