///

/// 判断面板中的所有控件是否为空 /// /// 如果不为空返回true,否则返回false bool IsNotEmpty() { // 定义一个字典,存储控件类型和判断控件是否为空的方法 Dictionary<Type, Func<FrameworkElement, bool>> validationMethods = new Dictionary<Type, Func<FrameworkElement, bool>>() { { typeof(TextBox), (element) => !string.IsNullOrEmpty(((TextBox)element).Text) }, { typeof(ComboBox), (element) => !string.IsNullOrEmpty(((ComboBox)element).Text) }, { typeof(DatePicker), (element) => !string.IsNullOrEmpty(((DatePicker)element).Text) } }; // 遍历面板中的所有控件 foreach (var element in Panel.Children.OfType()) { // 如果字典中存在该控件类型,则调用对应的判断方法判断控件是否为空 if (validationMethods.TryGetValue(element.GetType(), out var validationMethod)) { if (!validationMethod(element)) { return false; } } } return true;

summary 判断是否为空 summary returnsreturns bool IsNotEmpty DictionaryType FuncFrameworkElement bool validationMethods = new DictionaryType FuncFrameworkEle

原文地址: https://www.cveoy.top/t/topic/cEXc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录