/// <summary> Добавляет на EditingArea свойство объекта для редактирования </summary> private void AddPropertyToEditingArea(PropertyInfo property) { EditingPropertyAttribute attribute = property.GetAttribute <EditingPropertyAttribute>() as EditingPropertyAttribute; StackPanel stackPanel; if (attribute.IsInitializedByString) { stackPanel = (this.TabControl.Items.GetTabItem(attribute.GetTabItemName()).Content as ScrollViewer).Content as StackPanel; } else { stackPanel = ((this.TabControl.Items[attribute.GetTabItemNumber()] as TabItem).Content as ScrollViewer).Content as StackPanel; } stackPanel.Children.Add(this.CreatePanel(property)); }
/// <summary> Возвращает необходимый свойству FrameworkElement </summary> private Control GetControl(PropertyInfo property) { Control Result = null; if (property.PropertyType == typeof(string)) { LimitAttribute limitAttribute = property.GetAttribute <LimitAttribute>() as LimitAttribute; Result = new TextBox(); if (limitAttribute != null) { (Result as TextBox).MaxLength = limitAttribute.UpLimit; } } else if (property.PropertyType == typeof(int)) { LimitAttribute limitAttribute = property.GetAttribute <LimitAttribute>() as LimitAttribute; Result = new IntegerUpDown(); if (limitAttribute != null) { (Result as IntegerUpDown).Minimum = limitAttribute.LowLimit; (Result as IntegerUpDown).Maximum = limitAttribute.UpLimit; } } else if (property.PropertyType == typeof(bool)) { Result = new CheckBox(); } else if (property.PropertyType == typeof(double)) { Result = new DoubleUpDown(); } else if (property.PropertyType == typeof(id)) { Result = new TextBox() { IsEnabled = false }; } else if (property.PropertyType == typeof(DateTime)) { Result = new DatePicker(); } else if (property.PropertyType.IsEnum) { Result = new ComboBox(); (Result as ComboBox).SelectionChanged += (s, eventArgs) => { if (DataContext != null) { if ((s as ComboBox).SelectedIndex != -1) { property.SetValue(DataContext, new EnumToIntConverter().ConvertBack((s as ComboBox).SelectedIndex, property.PropertyType, null, null), null); } } else { System.Windows.MessageBox.Show("Редактируемый объект не выбран!", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }; this.AddItems(Result as ComboBox, property.PropertyType); } else if (property.PropertyType == typeof(bool?)) { Result = new ToggleButton() { IsThreeState = true }; Binding binding = new Binding(property.Name); binding.Mode = BindingMode.OneWay; binding.Converter = new NullableBoolToStringConverter(); BindingOperations.SetBinding(Result, ToggleButton.ContentProperty, binding); } else if (property.PropertyType.Is <DBObject>()) { Result = new DBObjectSelector(property); } if (property.PropertyType != typeof(id)) { EditingPropertyAttribute editingPropertyAttribute = property.GetAttribute <EditingPropertyAttribute>(); Result.IsEnabled = !editingPropertyAttribute.IsReadOnly; } Result.MinHeight = 24; Result.VerticalAlignment = System.Windows.VerticalAlignment.Center; return(Result); }