c# - Xaml Parse Exception WPF -
i have encountered problem whack mole game:
xamlparseexception unhandled
'the invocation of constructor on type 'whackamolereal.mainwindow' matches specified binding constraints threw exception.' line number '3' , line position '9'.
this main code:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.navigation; using system.windows.shapes; using system.windows.threading; using system.io; using teiutils; namespace whackamolereal { /// <summary> /// interaction logic mainwindow.xaml /// </summary> public partial class mainwindow : window { //global variables\\ string[] cmdargs = environment.getcommandlineargs(); string moleini; string root = ""; int imagesize; public mainwindow() { //setting .ini prefences\\ root = tutils.getinistring(moleini, "root", "path", ""); moleini = cmdargs[1]; initializecomponent(); // dispacher full game time \\ system.windows.threading.dispatchertimer endgame = new system.windows.threading.dispatchertimer(); endgame.tick += new eventhandler(endgame_tick); endgame.interval = timespan.fromseconds(5); endgame.start(); } private void endgame_tick(object sender, eventargs e) { this.close(); } private void populategrid() { double numofimages = tutils.getiniint(moleini, "numpictures", "pictures", 8); int imagesize = tutils.getiniint(moleini, "imagesize", "imagesize", 50); int imagebordersize = tutils.getiniint(moleini, "imageborder", "imageborder", 2); double numberofcolumns = tutils.getiniint(moleini, "numrowscolumns", "columnnum", 4); // more columns rows \\ if (numberofcolumns > numofimages) { messagebox.show("there wrong .ini file."); mainwin.close(); } // math - necessary variables \\ int columnsize = (imagesize + (4 * imagebordersize)); int rowsize = (imagesize + (4 * imagebordersize)); int numberofrows = (int)math.ceiling(numofimages / numberofcolumns); int mainwindowwidth = (tutils.toint(numberofcolumns.tostring(), 4) * columnsize) + 15; int mainwindowheight = (numberofrows * rowsize) + 35; // set window size \\ mainwin.width = mainwindowwidth; mainwin.height = mainwindowheight; // create grid \\ grid grid_main = new grid(); mainwin.content = grid_main; grid_main.height = mainwindowheight; grid_main.width = mainwindowwidth; // grid properties \\ (int = 0; < numberofcolumns; i++) { columndefinition newcolumn = new columndefinition(); newcolumn.width = new gridlength(columnsize, gridunittype.pixel); grid_main.columndefinitions.add(newcolumn); } (int = 0; < numberofrows; i++) { rowdefinition row = new rowdefinition(); row.height = new gridlength(rowsize, gridunittype.pixel); grid_main.rowdefinitions.add(row); } // fill grid \\ int rowcount = 0; int columncount = 0; (int = 0; < numofimages; i++) { // grid_main.children.add(grid_main); if (rowcount < numberofrows) { if (columncount < numberofcolumns) { console.writeline("columncount: " + columncount.tostring()); grid.setrow(createimage(), columncount); grid.setcolumn(createimage(), columncount); columncount++; } else { rowcount++; columncount = 0; grid.setrow(createimage(), columncount); grid.setcolumn(createimage(), columncount); columncount++; console.writeline("rowcount: " + rowcount.tostring()); } } else { break; } } } private image createimage() { // gets/sets necessary variables \\ double imageheight = imagesize * 0.7; // initialize image \\ system.windows.controls.image newimage = new image(); // image properties \\ newimage.width = imagesize; newimage.height = imageheight; // define name , content \\ newimage.name = "image"; string imagefunction = tutils.getinistring(moleini, "image", "picturefile", root + "mole2.png"); if (file.exists(imagefunction)) { newimage.source = new bitmapimage(new uri(imagefunction)); } else { messagebox.show("cannot find " + imagefunction + ".", "please fix ini file"); } return newimage; } } }
and xaml:
<window x:name="mainwin" x:class="whackamolereal.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <image margin="353,156,-131,-58" source="mole2.png" stretch="fill"/> <textblock horizontalalignment="left" margin="20,10,0,0" textwrapping="wrap" text="can catch mole?" verticalalignment="top" height="79" width="497" fontfamily="simhei" fontsize="40"/> </grid> </window>
environment.getcommandlineargs()
should return @ least array of 2 objects, since referring in constructor
moleini = cmdargs[1];
i tried out code. environment.getcommandlineargs()
returning 1 object.
Comments
Post a Comment