Grid alignment inside canvas in C# -


i working on windows phone project, requires me dynamically place grid inside canvas along 2 textblocks showing relevant data.

my code looks this.

            canvas canvas = new canvas();             canvas.height = height;             canvas.width = width;              grid grid = new grid();             grid.height = height;             grid.width = width;             grid.background = new solidcolorbrush(colors.green);             grid.showgridlines = true;             canvas.children.add(grid);              columndefinition c1 = new columndefinition();             c1.width = gridlength.auto;             columndefinition c2 = new columndefinition();             c2.width = gridlength.auto;              grid.columndefinitions.add(c1);             grid.columndefinitions.add(c2);              textblock wel_txt = new textblock();             wel_txt.text = wel.tostring();             wel_txt.textalignment = textalignment.center;             wel_txt.foreground = new solidcolorbrush(colors.white);             wel_txt.fontsource = slkscr;             wel_txt.fontfamily = new fontfamily(fontname);             wel_txt.fontsize = fontsize;              textblock tel_txt = new textblock();             tel_txt.text = tel.tostring();             tel_txt.textalignment = textalignment.center;             tel_txt.foreground = new solidcolorbrush(colors.white);             tel_txt.fontsource = slkscr;             tel_txt.fontfamily = new fontfamily(fontname);             tel_txt.fontsize = fontsize;              grid.children.add(wel_txt);             grid.children.add(tel_txt);             grid.setcolumn(tel_txt, 0);             grid.setcolumn(wel_txt, 1);              canvas.children.add(grid); 

ideally, code should create 2 columns in canvas, , place each textblock in column. aligned. both textblocks overlapping each other on top left corner of canvas.

what missing?


Comments