public override FrameworkElement CreateControl(FormItemContext context) { PasswordBox tb = new PasswordBox(); CustomValidation.SetValidationCallback(tb, () => { string errMsg = null; if (tb.Password == null || tb.Password.Length < 6) { errMsg = "密码强度不够"; } CustomValidation.SetValidationError(tb, errMsg); return(errMsg); }); tb.PasswordChanged += (s, e) => { CustomValidation.ForceValidation(tb); context.SetValueToBindedProperty(tb.Password); }; StyleHelper.ApplyStyle(tb, "editctl_pwd"); return(tb); }
public override FrameworkElement CreateControl(FormItemContext context) { // create control var border = new Border(); border.BorderThickness = new System.Windows.Thickness(4); var tb = new Label { Content = "尚未实现", Foreground = new SolidColorBrush(Colors.Gray), HorizontalAlignment = HorizontalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center }; border.Child = tb; // apply style StyleHelper.ApplyStyle(tb, "label_Label"); StyleHelper.ApplyStyle(border, "placeholder_br"); // set validation CustomValidation.SetValidationCallback(border, () => null); return(border); }
public override FrameworkElement CreateControl(FormItemContext context) { DatePicker picker = new DatePicker(); var binding = new Binding(context.PropertyInfo.Name) { Mode = BindingMode.TwoWay, }; binding.ValidationRules.Add(new AnnotationValidationRule(context.PropertyInfo)); picker.SetBinding(DatePicker.SelectedDateProperty, binding); CustomValidation.SetValidationProperty(picker, DatePicker.SelectedDateProperty); StyleHelper.ApplyStyle(picker, FormControlConstrants.EDIT_DATE_STYLE); return(picker); }
public FrameworkElement CreateControlForLookup(FormItemContext context, List <NameValuePair> options) { ComboBox cb = new ComboBox(); cb.ItemsSource = options; cb.SelectedValuePath = "Value"; var binding = new Binding(context.PropertyInfo.Name) { Mode = BindingMode.TwoWay, }; binding.ValidationRules.Add(new AnnotationValidationRule(context.PropertyInfo)); cb.SetBinding(ComboBox.SelectedValueProperty, binding); CustomValidation.SetValidationProperty(cb, ComboBox.SelectedValueProperty); StyleHelper.ApplyStyle(cb, FormControlConstrants.EDIT_COMBO_STYLE); return(cb); }
public override FrameworkElement CreateControl(FormItemContext context) { TextBox tb = new TextBox(); // apply [MaxLength(x)] attribute var attr2 = context.PropertyInfo.GetCustomAttribute(typeof(MaxLengthAttribute)) as MaxLengthAttribute; var attr3 = context.PropertyInfo.GetCustomAttribute(typeof(StringLengthAttribute)) as StringLengthAttribute; int maxlength = 0; if (attr2 != null) { maxlength = attr2.Length; } else if (attr3 != null) { maxlength = attr3.MaximumLength; } if (maxlength > 0) { tb.MaxLength = maxlength; } if (maxlength > 100) //TODO multiline mode { tb.TextWrapping = System.Windows.TextWrapping.Wrap; tb.AcceptsReturn = true; tb.Height = 50; } var binding = new Binding(context.PropertyInfo.Name) { Mode = BindingMode.TwoWay, }; binding.ValidationRules.Add(new AnnotationValidationRule(context.PropertyInfo)); tb.SetBinding(TextBox.TextProperty, binding); CustomValidation.SetValidationProperty(tb, TextBox.TextProperty); tb.GotFocus += (s, e) => { tb.SelectAll(); }; StyleHelper.ApplyStyle(tb, FormControlConstrants.EDIT_TEXTBOX_STYLE); return(tb); }
public override FrameworkElement CreateControl(FormItemContext context) { ComboBox cb = new ComboBox(); var enumtype = context.PropertyInfo.PropertyType; var source = EnumNameValuePair.EnumToList(enumtype); cb.ItemsSource = source; cb.SelectedValuePath = "Value"; var binding = new Binding(context.PropertyInfo.Name) { Mode = BindingMode.TwoWay, }; binding.ValidationRules.Add(new AnnotationValidationRule(context.PropertyInfo)); cb.SetBinding(ComboBox.SelectedValueProperty, binding); CustomValidation.SetValidationProperty(cb, ComboBox.SelectedValueProperty); StyleHelper.ApplyStyle(cb, FormControlConstrants.EDIT_COMBO_STYLE); return(cb); }