Search code examples
windows-phone-8layoutwindows-phone-8.1

how do i get rows and columns dynamically in windows phone app?


In my application i need to design the seat layout arrangement in the form of rows and columns dynamically. Please any one suggest me how to get rows and columns and which view i need to use.

this my xaml code

 <Grid x:Name="grid"  Background="White">
                <Button HorizontalAlignment="Stretch" Foreground="Black" Margin="23,56,268,527">Text</Button>
            </Grid>

this is .cs code

 for (int j = 0; j < jarray.Count; j++)
                   { 

                            grid.ColumnDefinitions.Add(new ColumnDefinition(){width=new GridLength(30)});           

                        grid.RowDefinitions.Add(new RowDefinition(){ Height = new GridLength(30) });

            }

but Iam getting empty page. Thank you in advance.


Solution

  • Updating suggestion here:

    you can use Grid Layout. Create a Grid in XAML and define Rowdefinition and ColumnDefinition dynamically in code behind and append to grid. If your xaml has Grid with name "grid" then in code behind you can rows and column like this. You can use loop for more number of rows and cols.

    grid.ColumnDefinitions.Add(new ColumnDefinition());
    grid.RowDefinitions.Add(new RowDefinition());
    

    Below are few links for ref:

    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/17093c72-cfce-40a2-a296-718b741b50da/how-to-dynamically-create-and-fill-grid-or-grid-view-from-c-not-xaml-becouse-i-am-dynamically?forum=winappswithcsharp

    Creating RowDefinitions and ColumnDefinitions in code