I was looking around on how to do a placeholder on WPF, and I found this answer (the first one).
The code given in the answer is here:
TextBox myTxtbx = new TextBox();
myTxtbx.Text = "Enter text here...";
myTxtbx.GotFocus += GotFocus.EventHandle(RemoveText);
myTxtbx.LostFocus += LostFocus.EventHandle(AddText);
void RemoveText(object sender, EventArgs e)
{
myTxtbx.Text = "";
}
void AddText(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(myTxtbx.Text))
myTxtbx.Text = "Enter text here...";
}
When I enter in my code, I get the following error:
The event 'UIElement.GotFocus' can only appear on the left hand side of += or -=
The event 'UIElement.LostFocus' can only appear on the left hand side of += or -=
I know what the error means, but I'm not sure what to do to fix the error and still get the desired result. Help would be greatly appreciated!