Vlopo123
Vlopo123

Reputation: 13

Can't seem to hide textBlock

i have fiddled around with C# quite a bit in the sense of making a webapp, however i decided i wanted to learn a bit more and ordered the book "Head First C#" fourth edition.

One of the first chapters guides you through making a matchup game but i'm getting stuck hiding the Emojis / textbox, they just stay visible when i launch.

Here's the C# code :

TextBlock lastTextBlockClicked;
    bool findingMatch = false;
    private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
    {
        TextBlock textBlock = sender as TextBlock;
        if (findingMatch == false)
        {
            textBlock.Visibility = Visibility.Hidden;
            lastTextBlockClicked = textBlock;
            findingMatch = true;
        }
        else if (textBlock.Text == lastTextBlockClicked.Text)
        {
            textBlock.Visibility = Visibility.Hidden;
            findingMatch = false;
        }
        else
        {
            lastTextBlockClicked.Visibility = Visibility.Visible;
            findingMatch = false;
        }
    }

And here's the XAML code.

<TextBlock Grid.Column="0" HorizontalAlignment="Center" Grid.Row="0" Text="?" VerticalAlignment="Center" FontSize="36" IsEnabled="False" MouseDown="TextBlock_MouseDown"/>

It's probably something extremely easy that i'm just overlooking but i've been trying for a while now.

Hope i can get some help from anyone, thank you in advance.

Upvotes: 0

Views: 122

Answers (1)

Nawed Nabi Zada
Nawed Nabi Zada

Reputation: 2875

When TextBlock is disabled == TextBlock.IsEnabled="False", the event MouseDown will not work. Change the IsEnabled="True" and it should work.

Upvotes: 1

Related Questions