public void ChangeType(ModelItemTypeEnum newType) { this.ObjectType = newType; this.uxContent.Content = null; FieldInformationAttribute fieldValues = (FieldInformationAttribute)this.PropertyInfo.GetCustomAttribute(typeof(FieldInformationAttribute)); this.CreateContent(this.parent, fieldValues); }
private void CreateObject(object parentObject) { FieldInformationAttribute fieldValues = (FieldInformationAttribute)this.PropertyInfo.GetCustomAttribute(typeof(FieldInformationAttribute)); ItemTypeAttribute itemType = (ItemTypeAttribute)this.PropertyInfo.GetCustomAttribute(typeof(ItemTypeAttribute)); this.valuesSource = (ValuesSourceAttribute)this.PropertyInfo.GetCustomAttribute(typeof(ValuesSourceAttribute)); this.HasFieldInformation = true; if (fieldValues == null) { fieldValues = new FieldInformationAttribute(this.PropertyInfo.Name); this.HasFieldInformation = false; } this.ObjectType = itemType == null?ModelItemType.GetItemType(this.PropertyInfo.PropertyType) : itemType.ModelType; this.isComboBoxEdit = itemType == null ? false : itemType.IsComboboxEditable; this.Visibility = fieldValues.IsVisible ? Visibility.Visible : Visibility.Collapsed; this.EitherOrGroupName = fieldValues.EitherOrGroupName; this.IsRequired = fieldValues.IsRequired; this.isSpellCheck = !fieldValues.DisableSpellChecker; this.Caption = fieldValues.FieldCaption; this.Sort = fieldValues.Sort; this.FontWeight = FontWeights.Normal; this.CreateContent(parentObject, fieldValues); this.AddBrowsable(); }
private void CreateContent(object parentObject, FieldInformationAttribute fieldValues) { BindingMode bindingMode = this.PropertyInfo.CanRead && this.PropertyInfo.CanWrite ? BindingMode.TwoWay : this.PropertyInfo.CanWrite ? BindingMode.OneWayToSource : BindingMode.OneWay; Binding binding = new Binding(this.PropertyInfo.Name) { Path = new PropertyPath(this.PropertyInfo.Name), Source = parentObject, Mode = bindingMode, BindsDirectlyToSource = true, }; binding.ValidationRules.Add(new IsRequiredValidationRule { IsRequired = fieldValues.IsRequired, ObjectType = this.ObjectType }); this.IsTabStop = !fieldValues.IsReadOnly; switch (this.ObjectType) { case ModelItemTypeEnum.CheckBox: #region CHECK BOX CheckBoxItem check = new CheckBoxItem { IsEnabled = !fieldValues.IsReadOnly }; check.GotFocus += this.Item_Focuesd; this.DependencyProperty = CheckBoxItem.IsCheckedProperty; check.SetBinding(CheckBoxItem.IsCheckedProperty, binding); this.BindingExpression = check.GetBindingExpression(CheckBoxItem.IsCheckedProperty); this.contentObject = check; break; #endregion case ModelItemTypeEnum.ComboBox: case ModelItemTypeEnum.EnumBox: #region COMBO BOX ComboBoxTool comboBox = new ComboBoxTool { IsEnabled = !fieldValues.IsReadOnly, IsEditable = this.isComboBoxEdit }; comboBox.HorizontalAlignment = HorizontalAlignment.Stretch; comboBox.GotFocus += this.Item_Focuesd; this.LoadContentValues(parentObject, comboBox); this.DependencyProperty = this.isComboBoxEdit ? ComboBoxTool.TextProperty : ComboBoxTool.ItemKeyProperty; comboBox.SetBinding(this.isComboBoxEdit ? ComboBoxTool.TextProperty : ComboBoxTool.ItemKeyProperty, binding); this.BindingExpression = comboBox.GetBindingExpression(this.isComboBoxEdit ? ComboBoxTool.TextProperty : ComboBoxTool.ItemKeyProperty); this.contentObject = comboBox; break; #endregion case ModelItemTypeEnum.DatePicker: #region DATE PICKER DatePicker date = new DatePicker { IsEnabled = !fieldValues.IsReadOnly }; //binding.ValidationRules.Clear(); date.HorizontalAlignment = HorizontalAlignment.Stretch; date.GotFocus += this.Item_Focuesd; this.DependencyProperty = DatePicker.SelectedDateProperty; date.SetBinding(DatePicker.SelectedDateProperty, binding); this.BindingExpression = date.GetBindingExpression(DatePicker.SelectedDateProperty); this.contentObject = date; break; #endregion case ModelItemTypeEnum.SecureString: #region SECURE STRING PasswordBoxBindable pass = new PasswordBoxBindable(parentObject) { IsEnabled = !fieldValues.IsReadOnly }; pass.HorizontalAlignment = HorizontalAlignment.Stretch; pass.HorizontalContentAlignment = HorizontalAlignment.Stretch; pass.LostFocus += this.Item_Focuesd; this.DependencyProperty = PasswordBoxBindable.PasswordTextProperty; pass.SetBinding(PasswordBoxBindable.PasswordTextProperty, binding); this.BindingExpression = pass.GetBindingExpression(PasswordBoxBindable.PasswordTextProperty); this.contentObject = pass; break; #endregion case ModelItemTypeEnum.ColorBox: case ModelItemTypeEnum.TextBox: default: #region TEXT BOX (DEFAULT) TextBoxItem text = new TextBoxItem { IsReadOnly = fieldValues.IsReadOnly, TextWrapping = TextWrapping.WrapWithOverflow }; text.MaxHeight = 250; text.MaxLength = fieldValues.MaxTextLength; text.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; text.HorizontalAlignment = HorizontalAlignment.Stretch; text.HorizontalContentAlignment = HorizontalAlignment.Stretch; text.SpellCheck.IsEnabled = this.isSpellCheck; text.LostFocus += this.Item_Focuesd; this.DependencyProperty = TextBoxItem.TextProperty; text.SetBinding(TextBoxItem.TextProperty, binding); this.BindingExpression = text.GetBindingExpression(TextBoxItem.TextProperty); this.contentObject = text; if (this.ObjectType == ModelItemTypeEnum.ColorBox && !text.Text.IsNullEmptyOrWhiteSpace()) { text.Background = ColourConverters.GetBrushfromHex(text.Text); text.Foreground = ColourConverters.InvertFromHex(text.Text); } break; #endregion } this.uxContent.Content = this.contentObject; }