因此,我创建了一个按钮,我想通过单击它来更改其文本。
这是我的代码背后的内容(来自Page_Load代码):
Button InviteToGameBTN = new Button();
InviteToGameBTN.Click += new EventHandler(InviteToGameBTN_OnClick);
。
protected void InviteToGameBTN_OnClick(object sender,EventArgs e)
{
Button b1 = (Button)sender;
b1.Text = "Text changed";
}
可能出什么事了?谢谢大家。
尝试一下:
public class Foo
{
public Foo()
{
Button myButton = new Button();
myButton.Content = "Old text";
myButton.Click += ButtonClicked;
yourGrid.Children.Add(myButton);
}
private void ButtonClicked(object sender, RoutedEventArgs e)
{
Button clickedButton = (Button) sender;
clickedButton.Content = "New text";
}
}