I
I
Ivan2020-02-27 01:01:24
WPF
Ivan, 2020-02-27 01:01:24

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>


cs code:
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

1 answer(s)
B
breathtaking, 2020-02-27
@Vamba45

In the line there is a comparison by reference, because class Useb.Content == "X"b.Contentobject
b.Content.ToString() == "X"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question