开发者

Array of Buttons in Windows Phone 7

I have defined my buttons in t开发者_StackOverflow社区he .xaml.

In the MainPage.xaml.cs I am trying to put them in an array.

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

I get the following error.

A field initializer cannot reference the non-static field, method, or property 'NoteTrainer_.MainPage.But_1'

If i put that array in the MainPage() constructor I get no errors,but then I cannot access the array from my methods.

Kinda new to C# and Windows-Phone

Thanks for the help.


Well, to start with that declaration looks wrong. But for a second thing, the compiler is telling you exactly what's wrong - you're trying to refer to one field within the initializer of another. Put the declaration as normal:

Button[] myButtons;

and then in the constructor you can use:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜