'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.
Solution 1:[1]
When TextBlock is disabled == TextBlock.IsEnabled="False", the event MouseDown will not work. Change the IsEnabled="True" and it should work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nawed Nabi Zada |
