为TextEdit增加水印
public static class TextEditHelper
{
//设置水印值
public static void SetWatermark(this TextEdit textEdit, string watermark)
{
textEdit.Properties.NullValuePromptShowForEmptyValue = true;
textEdit.Properties.NullValuePrompt = watermark;
}
//清除水印值
public static void ClearWatermark(this TextEdit textEdit)
{
if (textEdit.Properties.NullValuePromptShowForEmptyValue)
textEdit.Properties.NullValuePrompt = string.Empty;
}
}
- 上边的方法不仅适用于TextEdit,只要是文本输入类得控件都可以使用,如ComboBoxEdit、lookUpEdit等,因为其Properties属性都继承于RepositoryItemTextEdit基类