【问题标题】:Unable to assign name to polygon无法为多边形指定名称
【发布时间】:2013-01-12 16:48:56
【问题描述】:

我正在尝试为多边形指定名称,但是 Visual Studio 一直给我一个例外:

'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;
        }

【问题讨论】:

    标签: c# wpf polygon


    【解决方案1】:

    我相信您不能在 Name 属性中使用非法字符,即逗号。请尝试使用下划线。

    【讨论】:

    • 我将其更改为静态字符串,并且它似乎可以工作,但是当我尝试将变量分配为名称时,它会引发异常。
    • @TimoneUK 变量包含什么,GJHix 的想法是正确的,并且在我的测试中有效。您需要确保用于构造名称的变量中没有非法字符。
    • 变量只是 For 循环中的整数
    • 感觉自己像个笨蛋,因为我想给它起一个以数字开头的名字......
    • 感谢大家的帮助
    猜你喜欢
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多