Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 Windows Phone 7中的按钮阵列_Windows Phone 7 - Fatal编程技术网

Windows phone 7 Windows Phone 7中的按钮阵列

Windows phone 7 Windows Phone 7中的按钮阵列,windows-phone-7,Windows Phone 7,我已经在.xaml中定义了我的按钮 在MainPage.xaml.cs中,我试图将它们放入一个数组中 myButtons[]={But_1,But_2,But_n....}; 我得到以下错误 A field initializer cannot reference the non-static field, method, or property 'NoteTrainer_.MainPage.But_1' 如果我将该数组放在MainPage()构造函数中,我不会得到任何错误,但是我无法从我的

我已经在.xaml中定义了我的按钮

在MainPage.xaml.cs中,我试图将它们放入一个数组中

myButtons[]={But_1,But_2,But_n....};
我得到以下错误

A field initializer cannot reference the non-static field, method, or property 'NoteTrainer_.MainPage.But_1'
如果我将该数组放在MainPage()构造函数中,我不会得到任何错误,但是我无法从我的方法访问该数组

对C#和Windows Phone来说有点陌生


谢谢你的帮助。

好吧,从这个声明开始看起来是错误的。但是第二件事,编译器会告诉你到底哪里出了问题——你试图引用另一个初始值设定项中的一个字段。将声明视为正常:

Button[] myButtons;
然后在构造函数中,您可以使用:

myButtons = new[] { But_1, But_2, ... };

告诉我们您正在尝试做什么,因为按钮数组对我来说听起来非常VB6ish,我们可能能够引导您找到更好的解决方案。我正在做一个测试。我正在设置一个与数组中的按钮相等的按钮,例如correctButton=myButtons[1]。我已尝试将该数组放在加载、初始化等位置。。谢谢