The problem is that you are terminating the if-statement prematurely by a semicolon ;
!
if (textBlock.Text.Contains("Chocolate")) // <= removed the ";"
{
Uri Pure = new Uri("Images/ElfPortrait.png", UriKind.Relative);
BitmapImage imageSource = new BitmapImage(Pure);
image2.Source = imageSource;
}
Also the property is Text
with an upper case "T". In C# Text
and text
are two different identfiers!
Many programmers prefer to write the opening brace on the same line. This makes it clearer that the end of the line is not the end of a statement:
if (condition) {
statement-sequence
}
Note that "The Chocolate is fine!".Contains("Chocolate")
returns true
. If the whole string must be equal to the word then compare with textBlock.Text == "Chocolate"