private bool CheckGrid(Grid grid) { foreach (var child in grid.Children.OfType()) { if (child is TextBox textBox && string.IsNullOrEmpty(textBox.Text) || child is TextBlock textBlock && string.IsNullOrEmpty(textBlock.Text) || child is ComboBox comboBox && comboBox.SelectedItem == null || child is Grid childGrid && !CheckGrid(childGrid)) { return false; } } return true; }

C# 代码优化:检查 Grid 中子元素是否为空

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

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