Try adding these lines after BuyerPhoneNumber.Text = "":
BuyerPhoneNumber.UndoLimit = 0;
BuyerPhoneNumber.UndoLimit = -1;
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
First and foremost, I apologize for my grammatical errors; my first language is Persian (Iran).
I created a watermark for each of the Text Boxes in my project using the following method:
For example:
Language_TextBox.Foreground = Brushes.Silver;
Language_TextBox.Text = "Language";
private void Language_TextBox_GotFocus(object sender, RoutedEventArgs e)
{
try
{
switch ((Language_TextBox.Text == "Language") && Language_TextBox.Foreground == Brushes.Silver)
{
case true:
Language_TextBox.Text = "";
Language_TextBox.Foreground = Brushes.Black;
break;
}
}
catch
{
}
}
private void Language_TextBox_LostFocus(object sender, RoutedEventArgs e)
{
try
{
switch (Language_TextBox.Text == "" || Language_TextBox.Foreground == Brushes.Silver)
{
case true:
Language_TextBox.Foreground = Brushes.Silver;
Language_TextBox.Text = "Language";
break;
}
}
catch
{
}
}
Some Text Boxes are numeric Text Boxes, so I created a filter for their input using the following method:
private void BuyerPhoneNumber_TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
switch (!((e.Key >= Key.D0 && e.Key <= Key.D9) || (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || e.Key == Key.Back || e.Key == Key.Home || e.Key == Key.End || e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Tab || Keyboard.Modifiers == ModifierKeys.Control))
{
case true:
e.Handled = true;
break;
default:
switch (e.Key == Key.A || e.Key == Key.C || e.Key == Key.V || e.Key == Key.Y || e.Key == Key.Z)
{
case true:
break;
}
break;
}
}
But when I press Ctrl + Z or Ctrl + Y on the numeric Text Box, the watermark text (black watermark) is displayed in the Text Box:
The problem will be fixed if the watermark text color returns to the default (silver) state.
Thanks
Try adding these lines after BuyerPhoneNumber.Text = "":
BuyerPhoneNumber.UndoLimit = 0;
BuyerPhoneNumber.UndoLimit = -1;
If the following code is removed, the problem will be fixed, but the user can no longer use Undo and Redo capabilities: