| | |
| | | using HMI.Core.Util; |
| | | using Panuon.WPF.UI; |
| | | using System.Collections.Generic; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | |
| | |
| | | DependencyProperty.RegisterAttached("ValidateMethod", typeof(ValidateMethodDelegate), typeof(FormGroupHelper), |
| | | new PropertyMetadata(null)); |
| | | |
| | | public static bool ValidateForm(StackPanel fgPanel) |
| | | public static bool ValidateForm(StackPanel fgPanel, Dictionary<string, object> values = null) |
| | | { |
| | | if (fgPanel.Children == null) return true; |
| | | bool res = true; |
| | |
| | | { |
| | | if (child is FormGroup fg) |
| | | { |
| | | string fgName = fg.Name; |
| | | if (fg.Visibility != Visibility.Visible) |
| | | { |
| | | ClearValue(fg); |
| | |
| | | } |
| | | fg.ValidateResult = ValidateResult.None; |
| | | fg.Message = null; |
| | | object value; |
| | | if (values != null && values.ContainsKey(fgName)) |
| | | { |
| | | value = values[fgName]; |
| | | } |
| | | else |
| | | { |
| | | object content = fg.Content; |
| | | object value = GetValidateValue(content); |
| | | value = GetValidateValue(content); |
| | | } |
| | | |
| | | if (GetIsRequired(fg) && (value == null || string.IsNullOrEmpty(value.ToString()))) |
| | | { |
| | | fg.ValidateResult = ValidateResult.Error; |