如何使用C#为wp7中动态创建的文本框数组声明和使用事件处理程序



我是windows phone 7的新手。我动态地创建了一组文本框。我不知道在哪里以及如何声明和使用文本框的事件处理程序。我的代码如下所示:

 public partial class MainPage : PhoneApplicationPage
{
    public TextBox[] textbox;
    public MainPage()
    {
        InitializeComponent();
        string[] str = new string[2];
        str[0] = "force";
        str[1] = "force components";
         textbox = new TextBox[2];
        for (int i = 0; i < 2; i++)
        {
            textbox[i] = new TextBox { Text = str[i] };
    textbox[i].Tap += new System.EventHandler(this.textbox[i]_Tap);
            listBox1.Items.Add (textbox[i]);
        }
    }
private void textbox[0]_Tap(object sender, RoutedEventArgs e)
     {
     }
private void textbox[1]_Tap(object sender, RoutedEventArgs e)
     {
     }
 }

上面的代码显示了在声明和使用事件处理程序方法时的错误。请帮我写一段可以理解的代码,以清除我的错误。谢谢大家。

不能将方法命名为"private void textbox[1]_Tap"[]是不允许的。因此,即使你将其命名为"private void textbox1_Tap",当你在其中输入"i"时,你也无法调用该函数。

这是因为函数的名称是Reference,编译器稍后将不会记住变量、函数等的名称。

最新更新