Created
September 19, 2013 19:04
-
-
Save arnabdas/6628321 to your computer and use it in GitHub Desktop.
Dynamically add rows and columns in WPF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ContentPanel.ColumnDefinitions.Clear(); | |
| ContentPanel.RowDefinitions.Clear(); | |
| int numColumnsToAdd = 4; | |
| int numRowsToAdd = 4; | |
| for (int column = 0; column < numColumnsToAdd; column++) | |
| { | |
| ColumnDefinition cd = new ColumnDefinition(); | |
| cd.Width = new GridLength(200); | |
| ContentPanel.ColumnDefinitions.Add(cd); | |
| } | |
| for (int row = 0; row < numRowsToAdd; row++) | |
| { | |
| RowDefinition rd = new RowDefinition(); | |
| rd.Height = new GridLength(200); | |
| ContentPanel.RowDefinitions.Add(rd); | |
| } | |
| //add an image into each | |
| for (int row = 0; row < numRowsToAdd; row++) | |
| { | |
| for(int col = 0; col < numColumnsToAdd; col++) | |
| { | |
| TextBlock txt = new TextBlock(); | |
| txt.Text = "Hello"; | |
| ContentPanel.Children.Add(txt); | |
| Grid.SetColumn(txt, col); | |
| Grid.SetRow(txt, row); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment