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);
        }
Example #2
0
        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)
        {
            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 MatchResult MatchTest(FormItemContext context)
 {
     if (context.PropertyInfo.PropertyType == typeof(string))
         return MatchResult.Yes;
     else
         return MatchResult.No;
 }
 public override MatchResult MatchTest(FormItemContext context)
 {
     if (context.PropertyInfo.PropertyType == typeof(DateTime) ||
         context.PropertyInfo.PropertyType == typeof(Nullable<DateTime>))
         return MatchResult.Yes;
     else
         return MatchResult.No;
 }
 public override MatchResult MatchTest(FormItemContext context)
 {
     if (context.PropertyInfo.PropertyType.IsEnum)
     {
         return MatchResult.Yes;
     }
     else
         return MatchResult.No;
 }
Example #7
0
 public override MatchResult MatchTest(FormItemContext context)
 {
     if (context.PropertyInfo.PropertyType.IsEnum)
     {
         return(MatchResult.Yes);
     }
     else
     {
         return(MatchResult.No);
     }
 }
Example #8
0
 public override MatchResult MatchTest(FormItemContext context)
 {
     if (context.PropertyInfo.PropertyType == typeof(string))
     {
         return(MatchResult.Yes);
     }
     else
     {
         return(MatchResult.No);
     }
 }
 public override MatchResult MatchTest(FormItemContext context)
 {
     var attr = context.PropertyInfo.GetCustomAttribute(typeof(UIHintAttribute)) as UIHintAttribute;
     if (context.PropertyInfo.PropertyType==typeof(string)
         && attr != null
         && string.Equals(attr.UIHint, "password", StringComparison.OrdinalIgnoreCase))
     {
         return MatchResult.Recommanded;
     }
     else
         return MatchResult.No;
 }
Example #10
0
 public override MatchResult MatchTest(FormItemContext context)
 {
     if (context.PropertyInfo.PropertyType == typeof(DateTime) ||
         context.PropertyInfo.PropertyType == typeof(Nullable <DateTime>))
     {
         return(MatchResult.Yes);
     }
     else
     {
         return(MatchResult.No);
     }
 }
        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;
        }
Example #12
0
        public override MatchResult MatchTest(FormItemContext context)
        {
            var attr = context.PropertyInfo.GetCustomAttribute(typeof(UIHintAttribute)) as UIHintAttribute;

            if (context.PropertyInfo.PropertyType == typeof(string) &&
                attr != null &&
                string.Equals(attr.UIHint, "password", StringComparison.OrdinalIgnoreCase))
            {
                return(MatchResult.Recommanded);
            }
            else
            {
                return(MatchResult.No);
            }
        }
Example #13
0
        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;
        }
Example #15
0
        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);
        }
Example #16
0
        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);
        }
        internal FrameworkElement RenderSelectUserControl(FormItemContext context, WarehouseContext dbcontext,
                                                          User selecteduser = null)
        {
            var options = (from u in dbcontext.Users
                           select new NameValuePair
            {
                Name = u.Name,
                Description = u.IdentificationNumber,
                Value = u
            }).ToList();
            var ctl = new ComboBoxSink().CreateControlForLookup(context, options);

            if (selecteduser != null)
            {
                var selectedop = options.FirstOrDefault(o => ((User)o.Value).UserId == selecteduser.UserId);
                ((ComboBox)ctl).SelectedValue = selectedop.Value;
            }
            return(ctl);
        }
        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;
        }
        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;
        }
Example #20
0
        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);
        }
        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 MatchResult MatchTest(FormItemContext context)
 {
     return MatchResult.NotRecommanded;
 }
 public abstract MatchResult MatchTest(FormItemContext context);
 public abstract FrameworkElement CreateControl(FormItemContext context);
 public abstract FrameworkElement CreateControl(FormItemContext context);
 public abstract MatchResult MatchTest(FormItemContext context);
 public override MatchResult MatchTest(FormItemContext context)
 {
     return(MatchResult.NotRecommanded);
 }