Forum Xamarin Xamarin.Forms

[Bug] Grid ColumnDefination & RowDefination

eye_v_eyeeye_v_eye Member ✭✭

I am trying to change the width of the Column and height of the row programmatically. However I found out, whenever I change any of the Column or Row, the rest will follow. Is this a bug?

private void GenerateControl()
        {
            Grid grid = new Grid();

            var r = new RowDefinition();
            var c = new ColumnDefinition();
            for (int i = 0; i < 3; i++)
            {
                r.Height = 100;
                c.Width = 100;

                grid.ColumnDefinitions.Add(c);
                grid.RowDefinitions.Add(r);
            }

            TestLayout.Children.Clear();
            TestLayout.Children.Add(grid);
            foreach (var CD in grid.ColumnDefinitions)
            {
                Debug.WriteLine("Before - Col: " + CD.Width.ToString());
            }
            foreach (var CR in grid.RowDefinitions)
            {
                Debug.WriteLine("Before - Row " + CR.Height.ToString());
            }
            grid.ColumnDefinitions[0].Width = 50;
            grid.RowDefinitions[0].Height = 50;

            foreach (var CD in grid.ColumnDefinitions)
            {
                Debug.WriteLine("After - Col: " +CD.Width.ToString());
            }
            foreach (var CR in grid.RowDefinitions)
            {
                Debug.WriteLine("After - Row " + CR.Height.ToString());
            }
        }

Output:
[0:] Before - Col: 100.Absolute
[0:] Before - Col: 100.Absolute
[0:] Before - Col: 100.Absolute
[0:] Before - Row 100.Absolute
[0:] Before - Row 100.Absolute
[0:] Before - Row 100.Absolute
[0:] After - Col: 50.Absolute
[0:] After - Col: 50.Absolute
[0:] After - Col: 50.Absolute
[0:] After - Row 50.Absolute
[0:] After - Row 50.Absolute
[0:] After - Row 50.Absolute

Tagged:
Sign In or Register to comment.