c# - WPF Forms - 如何在文本框上添加文本占位符
问题描述
一般来说,我对 WPF 和 C# 很陌生。我正在尝试在我的文本框上添加一个文本框,当您专注于文本框时,我希望文本消失,如果我移动到其他内容(也就是失去焦点),并且文本为空,我希望文本框添加文本我想要文本返回。
但我在 GotFocus.EventHandle(RemoveText); 上收到错误 和 LostFocus.EventHandle(AddText); 关于“GotFocus”和“Lostfocus”这两个词(在下面的代码中)
我错过了什么?
我尝试了下一个代码:
ExcelPath.Text = "Please Drag Excel into here";
ExcelPath.GotFocus += GotFocus.EventHandle(RemoveText);
ExcelPath.LostFocus += LostFocus.EventHandle(AddText);
public void RemoveText(object sender, EventArgs e)
{
if (ExcelPath.Text == "Please Drag Excel into here")
{
ExcelPath.Text = "";
}
}
public void AddText(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(ExcelPath.Text))
ExcelPath.Text = "Please Drag Excel into here";
}
解决方案
这是连接事件处理程序的语法:
ExcelPath.Text = "Please Drag Excel into here";
ExcelPath.GotFocus += RemoveText;
ExcelPath.LostFocus += AddText;
摆脱GotFocus.EventHandle
那是什么。
推荐阅读
- php - Niginx 下载 PHP 文件而不是执行 index.php
- php - Docker nginx 和 php-fpm
- android - 清单中存在时未授予运行时权限(Android)
- node.js - 如何在 cpanel 中运行节点应用程序以及设置 .htaccess 文件所需的内容
- php - nginx api/index.php/explorer url 给出 404 错误
- css - Bootstrap - 类文本中心不适用于内部 div
- java - 在 Servlet 中下载文件
- c# - 按 List 中的数据对 DataTable 进行排序
- c# - 从 xml 文件填充 Datagrid
- java - Random.nextBytes(byte[]) 在java中的行为