WPF 检查控件文本是否为空的最佳方法
可以使用以下代码来判断控件的 Text 是否为空:
foreach (var t in Panel.Children)
{
if (t is Control control)
{
if (string.IsNullOrEmpty(control.Text))
{
// Text 为空
}
else
{
// Text 不为空
}
}
}
其中,string.IsNullOrEmpty() 方法用于判断字符串是否为空或 null。如果为空或 null,返回 true,否则返回 false。
原文地址: https://www.cveoy.top/t/topic/j44X 著作权归作者所有。请勿转载和采集!