question

84831950 avatar image
0 Votes"
84831950 asked LeonLu-MSFT commented

Strange behavior with Grid definition auto height and stacklayout inside the row

Hello,

I am using a grid with autoheight for row definition (I have a Editor inside, so my row can update it's height depending of the text).

My issue is, in another cell, there is a stack layout

StackLayout stackEspeceVariete = new StackLayout()
                    {
                        Children = { autoCompleteEspece, autoCompleteVariete }
                    };
                    stackEspeceVariete.Orientation = StackOrientation.Horizontal;

                    gridLignes.Children.Add(stackEspeceVariete);
                    Grid.SetRow(stackEspeceVariete, gridLignes.RowDefinitions.Count - 1);
                    Grid.SetColumn(stackEspeceVariete, 2);


Adding the stacklayout cause my row to take all the screen size. I want the stacklayout to take the size it's needed, not all screen size.

I tried changing the vertical option but no success.

I also tried to fix the stacklayout height to 130, it's was "working" but, the row height was no longer changing, depending on the editor text.

It's like the row is fixed to the stacklayout child

Do you have any idea ?

Thanks

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

Are autoCompleteEspece and autoCompleteVariete Editor ?

If so, please add HorizontalOptions = LayoutOptions.FillAndExpand, in the stackEspeceVariete, then set stackEspeceVariete.Orientation = StackOrientation.Vertical; ,do not forget to add the AutoSize for your two Editor like following code.


public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

            var autoCompleteEspece = new Editor();
            autoCompleteEspece.AutoSize = EditorAutoSizeOption.TextChanges;


            var autoCompleteVariete = new Editor();
            autoCompleteVariete.AutoSize = EditorAutoSizeOption.TextChanges;
            StackLayout stackEspeceVariete = new StackLayout()
            {
                Children = { autoCompleteEspece , autoCompleteVariete },
                BackgroundColor = Color.AliceBlue,
                HorizontalOptions = LayoutOptions.FillAndExpand,
               
            };
            stackEspeceVariete.Orientation = StackOrientation.Vertical;
            // gridLignes.Children.Add(stackEspeceVariete);
          

            MyGrid.Children.Add(stackEspeceVariete);
        }
    }


Here is my xaml layout code.

<StackLayout>
        <Grid x:Name="MyGrid"  BackgroundColor="Red">
            <Grid.RowDefinitions>
               
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
               
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            

        </Grid>
    </StackLayout>




Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@84831950 May I know if you have got any chance to check my answer?

0 Votes 0 ·