Metro App: How i can define row and column defination dynamically RRS feed

  • Question

  • Hi All,

    please help me to define row and column defination dynamically in Grid. I want  some thing like this

    where the column can increase to 5.8 and 5.9 or it may decrease based on the input.



    Wednesday, August 21, 2013 2:23 PM


  • You can create RowDefinitions and ColumnDefinitions in code similar to how you would do so in Xaml. Here's a quick sample snippet.

                RowDefinition rowDef = new RowDefinition();
                for (int i = 51; i < 60; i++)
                    ColumnDefinition colDef = new ColumnDefinition();
                    colDef.Width = new GridLength(50, GridUnitType.Pixel);
                    TextBlock text = new TextBlock();
                    text.Text = (i / 10.0).ToString();
                    text.SetValue(Grid.RowProperty, 0);
                    text.SetValue(Grid.ColumnProperty, i - 51);

    This isn't something I'd use in a production app, but I'm not sure what you are really looking for here. You'd probably be better off with a databound ItemsControl of some sort, but without context I don't know what exactly you would want to do here.


    Thursday, August 22, 2013 12:55 AM