Answer the question
In order to leave comments, you need to log in
I can not understand why the program works, but not quite correctly ..?
I wrote a handler for the button click event, everything works, but only the text (the Content property on the button) does not change the first time, but only the second, the message displayed by the MessageBox is displayed on the 1st try, memory)) 0
XAML code:
<StackPanel Grid.Row="0"
Grid.Column="0">
<Button Name="button1" Click="Button_Click"
Content="X">
</Button>
</StackPanel>
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Button is ready");
Button b = (Button)sender;
if(b.Content == "X")
{
b.Content = "Y";
}
else
{
b.Content = "X";
}
}
Answer the question
In order to leave comments, you need to log in
In the line there is a comparison by reference, because class
Useb.Content == "X"
b.Content
object
b.Content.ToString() == "X"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question