2013-01-12 34 views
0

我想指定名稱爲多邊形,但是視覺工作室一直給我一個例外:無法指定名稱多邊形

'The invocation of the constructor on type 'Isometric_Turtle_Simulator.MainWindow' that  matches the specified binding constraints threw an exception.' Line number '3' and line position '9'. 

我的代碼是:

 for (int a = 0; a < z; a++) 
     { 
      for (int b = 0; b < x; b++) 
      { 
       for (int c = 0; c < y; c++) 
       { 
        tile = getTile.genTile(worldData[a,b,c]); 
        tile.Name = a.ToString() + "," + b.ToString() + "," + c.ToString(); 
        Canvas.SetTop(tile, posY); 
        Canvas.SetLeft(tile, posX); 
        mainCanvas.Children.Add(tile); 
        tile.MouseDown += (sender, e) => mouseDownEvent(sender, e); 
        posY = posY + 15; 
        posX = posX + 30; 
       } 
       posY = posY - 15 * (x - 1); 
       posX = posX - 30 * (y + 1); 
      } 
      posX = posXOrigin; 
      posY = posY - (35 + (15 * x)); 
      Height = Height + 35; 
      mainCanvas.Height = Height; 
     } 

回答

3

我相信你在Name屬性中不能有非法字符,即逗號。嘗試使用下劃線代替。

+0

剛試過這個,仍然得到相同的錯誤-_- – TimoneUK

+0

我改變它,所以它是一個靜態字符串,它似乎工作,但是當我嘗試並分配一個變量作爲名稱時,它會引發異常。 – TimoneUK

+0

@TimoneUK這些變量包含什麼,GJHix的想法是正確的,並在我的測試中起作用。您需要確保在用於構造名稱的變量中沒有非法字符。 –