在 windows 商店应用程序中生成一个矩形

Generating a rectangle in windows store app

我正在尝试在 windows 商店应用程序中按下按钮时动态生成一个矩形 我试过了

Rect r = new Rect();

myGrid.Children.Add(r);

但它给我一个错误
"The best overloaded method match for 'name' has some invalid arguments"

有什么问题?

Rect 是一个简单的结构。你想要 Rectangle

尝试

Rectangle r = new Rectangle();
myGrid.Children.Add(r);

查看 this 了解更多信息。