| | |
| | | using System; |
| | | using System.ComponentModel; |
| | | using HMI.Core.Util; |
| | | using Panuon.WPF.UI; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | using Panuon.WPF.UI; |
| | | using Panuon.WPF.UI.Configurations; |
| | | |
| | | namespace HMI.UI |
| | | namespace HMI.UI.DpUtil |
| | | { |
| | | public class FormGroupHelper |
| | | { |
| | |
| | | new PropertyMetadata(false, (d, e) => |
| | | { |
| | | if (!(d is FormGroup fg)) return; |
| | | if ((bool)e.NewValue) |
| | | if ((bool)e.NewValue && !string.IsNullOrEmpty(fg.Header?.ToString())) |
| | | { |
| | | var style = Application.Current.FindResource("RequiredInputFormGroupStyle") as Style; |
| | | fg.Style = style; |
| | | var dataTemplate = Application.Current.FindResource("RequiredFormHeader") as DataTemplate; |
| | | fg.HeaderTemplate = dataTemplate; |
| | | } |
| | | else |
| | | { |
| | | var style = Application.Current.FindResource("RequiredInputFormGroupStyle") as Style; |
| | | fg.Style = style; |
| | | fg.HeaderTemplate = null; |
| | | } |
| | | })); |
| | | |
| | |
| | | { |
| | | if (child is FormGroup fg) |
| | | { |
| | | fg.ValidateResult = ValidateResult.None; |
| | | fg.Message = null; |
| | | object content = fg.Content; |
| | | object value = GetValidateValue(content); |
| | | if (value != null && GetIsRequired(fg) && string.IsNullOrEmpty(value.ToString())) |
| | | if (GetIsRequired(fg) && (value == null || string.IsNullOrEmpty(value.ToString()))) |
| | | { |
| | | fg.ValidateResult = ValidateResult.Error; |
| | | fg.Message = $"{fg.Header}不能为空"; |
| | | fg.Message = string.Format(LangUtil.Get("App.CantBeEmpty"), fg.Header); |
| | | res = false; |
| | | } |
| | | else |
| | |
| | | return elementCollection.Count > 0 ? GetValidateValue(elementCollection[0]) : null; |
| | | if (content is TextBox tb) return tb.Text; |
| | | if (content is CheckBox cb) return cb.IsChecked; |
| | | if (content is ComboBox cBox) return cBox.Text; |
| | | if (content is ComboBox cBox) return cBox.SelectedItem ?? cBox.SelectedValue ?? cBox.Text; |
| | | |
| | | if (content is Panel panel) return GetValidateValue(panel.Children); |
| | | if (content is NumberInput numberInput) return numberInput.Value; |
| | | if (content is Panuon.WPF.UI.NumberInput numberInput) return numberInput.Value; |
| | | if (content is PasswordBox passwordInput) return passwordInput.Password; |
| | | return null; |
| | | } |
| | | } |