首页 > 代码库 > C# WPF 之 遍历子控件
C# WPF 之 遍历子控件
/// <summary> /// 检查非空字段 /// </summary> /// <param name="IsOk"></param> /// <param name="textboxes"></param> private void CheckTextBoxNotNull(ref bool IsOk, params TextBox[] textboxes) { foreach (TextBox txtBox in textboxes) { txtBox.Background = Brushes.White; if (txtBox.Text.Length <= 0) { IsOk = false; txtBox.Background = Brushes.Red; } else { txtBox.Background = null; } } }
/// <summary> /// 设置控件 /// </summary> /// <param name="IsEn"></param> /// <param name="IsNull"></param> private void SetControl(bool IsEn ,bool IsNull) { foreach (UIElement c in grd_UserInfo.Children) { if (c is TextBox) { c.IsEnabled = IsEn; if (IsNull) { ((TextBox)c).Text = ""; } } if (c is ComboBox) { c.IsEnabled = IsEn; if (IsNull) { ((ComboBox)c).SelectedIndex = -1; } } if (c is DatePicker) { c.IsEnabled = IsEn; if (IsNull) { ((DatePicker)c).SelectedDate = null; } } } btn_ChoosePhoto.IsEnabled = IsEn; }
/// <summary> /// 验证邮箱输入是否合法 /// </summary> /// <param name="strIn"></param> /// <returns></returns> private bool IsValidEmail(string strIn) { return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。