我有一个文本框,它不允许用户输入“[”和“]”字符。但是,我想将文本设置为默认包含“[”和“]”的值。我该怎么办?这是我的代码:
TextBox txtEdit = new TextBox();
txtEdit.TextChanged += txtEdit_TextChanged;
txtEdit.Text = "[Test]";
private void txtEdit_TextChanged(object sender, TextChangedEventArgs e)
{
if ((sender as TextBox).Text.Contains("[") || (sender as TextBox).Text.Contains("]"))
{
MessageBox.Show("Cannot enter '[' or ']' characters!", "", MessageBoxButton.OK, MessageBoxImage.Information);
(sender as TextBox).Text = "";
}
}