c# - How to dynamically create asymmetric grid in WPF -
first things first, aware there 100s of questions similar haven't found 1 tackles kind of problem.
so, want build grid 2 or more columns, each of have 3 or more rows. columns have equal width rows can have different height. grid created on application start-up , data read .xml file , stored in arrays.
since ui isn't symmetric, don't know how point using correct wpf methodology. appreciate if show me example code use figure out correct way code this.
private void createdynamicwpfgrid() { // data read file int columns_count = 2; int[] row_counts = { 4, 3 }; int[,] sizes = { { 2, 1, 1, 1}, { 1, 1, 2, 0 } }; // create parent grid grid parentgrid = new grid(); parentgrid.width = ((system.windows.controls.panel)application.current.mainwindow.content).actualwidth; parentgrid.height = ((system.windows.controls.panel)application.current.mainwindow.content).actualheight; parentgrid.showgridlines = true; // create columns (int = 0; < columns_count; i++) { columndefinition parentcol = new columndefinition(); parentgrid.columndefinitions.add(parentcol); // create child grid in column grid childgrid = new grid(); childgrid.showgridlines = true; columndefinition childcol = new columndefinition(); childgrid.columndefinitions.add(childcol); // create rows in child grid (int j = 0; j < row_counts[i]; j++) { rowdefinition childrow = new rowdefinition(); childrow.height = new gridlength(sizes[i, j], gridunittype.star); childgrid.rowdefinitions.add(childrow); } // set location grid.setcolumn(childgrid, i); grid.setrow(childgrid, 0); parentgrid.children.add(childgrid); } // display grid window this.content = parentgrid; }
Comments
Post a Comment