[英]WIndows Phone C# change content button AFTER CLICK
I'm starting my adventure with C# and writting apps on Windows Phone, but I stucked a little. 我开始使用C#冒险,并在Windows Phone上编写应用程序,但是我有些犹豫。 I am writting an easy game noughts and crosses. 我正在写一个简单的游戏。
I have a button: 我有一个按钮:
<Button Content=" " HorizontalAlignment="Left" Height="126" Margin="37,146,0,0" VerticalAlignment="Top" Width="126" Click="a0"/>
And I wish that after clicking the content would change to X, like 我希望在单击内容后将其更改为X,例如
public void a0(object sender, System.EventArgs e)
{
a0.Content = "X";
}
But I know that's impossible. 但是我知道那是不可能的。 How can I do this? 我怎样才能做到这一点? :( :(
sender
parameter is the object that triggers the event. sender
参数是触发事件的对象。 So you can use it to access your button: 因此,您可以使用它来访问按钮:
var btn = sender as Button;
if(btn != null)
{
btn.Content = "X";
}
Check x:Name Directive . 检查x:Name指令 。
If you are going to use it, assign the name to the button. 如果要使用它,请将名称分配给按钮。
x:Name = "btnA0"
Later in button click event handler: 稍后在按钮单击事件处理程序中:
btnA0.Content = "ButtonNewContent";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.