private UserControls.ListControls.Item AddNewListItem(object item, System.Collections.IList list, UserControls.ListControls.GroupCard rootFieldGroupCard, string fieldName) { var listControlItem = new UserControls.ListControls.Item(); var ProcessedClass = ProcessClass(item); ProcessedClass.ForEach(control => { listControlItem.ControlWrapPanel.Children.Add(control); }); listControlItem.DeleteItemIcon.MouseLeftButtonUp += (s, e) => { var deleteItemMessageBox = new Windows.AFG_MessageBox("Remove Item?", "Are you sure you want to remove this?"); deleteItemMessageBox.ShowDialog(); if (deleteItemMessageBox.MessageBoxResult == MessageBoxResult.Yes) { rootFieldGroupCard.ControlsWrapPanel.Children.Remove(listControlItem); list.Remove(item); OnPropertyModified?.Invoke(fieldName, null); } }; return(listControlItem); }
private UserControls.ListControls.Item AddNewItemListItem(FormControlSettings controlSettings, UserControls.ListControls.GroupCard rootFieldGroupCard, System.Collections.IList list, string fieldName) { var userControl = HandleUserControl(controlSettings); if (userControl != null) { var listControlItem = new UserControls.ListControls.Item(); listControlItem.ControlWrapPanel.Children.Add(userControl); listControlItem.DeleteItemIcon.MouseLeftButtonUp += (s, e) => { var deleteItemMessageBox = new Windows.AFG_MessageBox("Remove Item?", "Are you sure you want to remove this?"); deleteItemMessageBox.ShowDialog(); if (deleteItemMessageBox.MessageBoxResult == MessageBoxResult.Yes) { rootFieldGroupCard.ControlsWrapPanel.Children.Remove(listControlItem); list.Remove(controlSettings.Value); OnPropertyModified?.Invoke(fieldName, null); } }; return(listControlItem); } return(null); }
private void Slider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { Slider.ToolTip = e.NewValue.ToString(CultureInfo.InvariantCulture) + "%"; if (DisplayLabel != null) { DisplayLabel.Content = e.NewValue.ToString(CultureInfo.InvariantCulture) + "%"; } OnPropertyModified?.Invoke("", Convert.ToSingle(e.NewValue / 100)); }
private UserControl BuildControl(FormControlSettings formControlSettings) { UserControl userControl = null; switch (formControlSettings.ObjectType) { case ObjectTypes.String: var stringField = new StringField(); stringField.BuildDisplay(formControlSettings); if (formControlSettings.Required) { OnValidate += stringField.Validate; } stringField.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); stringField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); OnAddFieldInsertItems += (Name, Items) => { if (Name == formControlSettings.FieldFullName) { stringField.AddDropdownItems(Items, formControlSettings.Value); } }; //OnSpecialDropdownDisplaying?.Invoke(formControlSettings.FieldFullName); userControl = stringField; break; case ObjectTypes.Password: var passwordField = new PasswordField(); passwordField.BuildDisplay(formControlSettings); if (formControlSettings.Required) { OnValidate += passwordField.Validate; } passwordField.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); passwordField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = passwordField; break; case ObjectTypes.Double: var doubleField = new DoubleField(); doubleField.BuildDisplay(formControlSettings); if (formControlSettings.Required) { OnValidate += doubleField.Validate; } doubleField.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); doubleField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = doubleField; break; case ObjectTypes.Int32: var intField = new IntField(); intField.BuildDisplay(formControlSettings); if (formControlSettings.Required) { OnValidate += intField.Validate; } intField.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); intField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = intField; break; case ObjectTypes.Single: var floatField = new FloatField(); floatField.BuildDisplay(formControlSettings); if (formControlSettings.Required) { OnValidate += floatField.Validate; } floatField.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); floatField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = floatField; break; case ObjectTypes.Boolean: var booleanField = new BooleanField(); booleanField.BuildDisplay(formControlSettings); if (formControlSettings.Required) { OnValidate += booleanField.Validate; } booleanField.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); booleanField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = booleanField; break; case ObjectTypes.SpecialDropdown: var specialDropdown = new SpecialDropdownField(); specialDropdown.BuildDisplay(formControlSettings); if (formControlSettings.Required) { OnValidate += specialDropdown.Validate; } OnAddSpecialDropdownItems += (Name, Items) => { if (Name == formControlSettings.FieldFullName) { specialDropdown.AddDropdownItems(Items, formControlSettings.Value); } }; OnSpecialDropdownDisplaying?.Invoke(formControlSettings.FieldFullName, (Name, Items) => { if (Name == formControlSettings.FieldFullName) { specialDropdown.AddDropdownItems(Items, formControlSettings.Value); } }); specialDropdown.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); specialDropdown.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = specialDropdown; break; case ObjectTypes.FolderBrowser: var folderStringField = new FolderBrowserField(); folderStringField.BuildDisplay(formControlSettings); if (formControlSettings.Required) { OnValidate += folderStringField.Validate; } folderStringField.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); folderStringField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = folderStringField; break; case ObjectTypes.TimePicker: var timePickerField = new TimePickerField(); timePickerField.BuildDisplay(formControlSettings); timePickerField.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); timePickerField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = timePickerField; break; case ObjectTypes.Custom: if (formControlSettings.FormField.CustomControl != null && formControlSettings.FormField.CustomControl.GetInterface(typeof(ICustomControl).FullName) != null) { var customControlClass = (ICustomControl)Activator.CreateInstance(formControlSettings.FormField.CustomControl); if (!(customControlClass is UserControl)) { break; } var customControlBase = new CustomControlBase(); customControlBase.BuildDisplay(formControlSettings, customControlClass); customControlBase.OnControlModified += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s); customControlBase.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s); userControl = customControlBase; } break; } return(userControl); }
private List <UserControl> BuildUserControls(object Class, List <PropertyInfo> props) { var userControls = new List <UserControl>(); var SortedControls = new List <PropInfoSorterClass>(); var classType = Class.GetType(); double displayNameWidth = 0; double valueWidth = 100; foreach (var propInfo in props) { var formField = (FormField)propInfo.GetCustomAttributes(typeof(FormField), true).FirstOrDefault(); var displayValue = propInfo.Name; if (formField.DisplayName != string.Empty) { displayValue = formField.DisplayName; } if ((displayValue.Length * 10) > displayNameWidth) { displayNameWidth = (displayValue.Length * 10); } SortedControls.Add(new PropInfoSorterClass() { Order = formField.Order, PropertyInfo = propInfo }); } if (Attribute.IsDefined(classType, typeof(FormClass))) { var formClass = classType.GetCustomAttribute <FormClass>(); if (formClass.FormValueWidth != -1) { valueWidth = formClass.FormValueWidth; } if (formClass.WidthOverride) { displayNameWidth = Double.NaN; } } var PropInfoSorterClasses = SortedControls.OrderBy(a => a.Order).ToList(); foreach (var propInfo in PropInfoSorterClasses) { var FormField = (FormField)propInfo.PropertyInfo.GetCustomAttributes(typeof(FormField), true).FirstOrDefault(); if (FormField == null) { continue; } var ObjectType = FormField.ObjectTypeName; if (FormField.ObjectTypeName == ObjectTypes.Default) { if (!Enum.IsDefined(typeof(ObjectTypes), propInfo.PropertyInfo.PropertyType.Name)) { continue; } ObjectType = (ObjectTypes)Enum.Parse(typeof(ObjectTypes), propInfo.PropertyInfo.PropertyType.Name); } var formControlSettings = new FormControlSettings { DisplayNameWidth = displayNameWidth, ValueWidth = valueWidth, FieldName = propInfo.PropertyInfo.Name, Value = propInfo.PropertyInfo.GetValue(Class), ObjectType = ObjectType, FormField = FormField, ClassType = classType }; formControlSettings.OnValueChanged += value => { try { propInfo.PropertyInfo.SetValue(Class, value); } catch { } }; var userControl = HandleUserControl(formControlSettings); if (userControl != null) { userControls.Add(userControl); } } PropInfoSorterClasses.ForEach(clase => { OnPropertyModified?.Invoke(classType.FullName + "." + clase.PropertyInfo.Name, clase.PropertyInfo.GetValue(Class)); }); return(userControls); }
private IEnumerable <UserControl> HandleNestedList(object rootClass) { var rootClassType = rootClass.GetType(); var nestedLists = Helpers.GetProperties(rootClassType, Types.NestedList); var normalItems = Helpers.GetProperties(rootClassType, Types.Prop); normalItems.ForEach(info => { if (info.PropertyType.IsGenericType && info.PropertyType.GetGenericTypeDefinition() == typeof(List <>)) { nestedLists.Add(info); } }); var userControls = new List <UserControl>(); nestedLists.ForEach(propInfo => { var formField = (FormField)propInfo.GetCustomAttributes(typeof(FormField), true).FirstOrDefault(); var rootFieldGroupCard = new UserControls.ListControls.GroupCard(); var list = (System.Collections.IList)propInfo.GetValue(rootClass, null); var listType = propInfo.PropertyType.GetGenericArguments()[0]; if (formField.NestedListClassType != null) { listType = formField.NestedListClassType; } if (list == null) { var constructedListType = typeof(List <>).MakeGenericType(listType); list = Activator.CreateInstance(constructedListType) as System.Collections.IList; } var displayName = propInfo.Name; var fieldName = rootClassType.FullName + "." + propInfo.Name; if (formField.DisplayName != string.Empty) { displayName = formField.DisplayName; } rootFieldGroupCard.AddItemIcon.MouseLeftButtonUp += (s, e) => { var nestedItem = Activator.CreateInstance(listType); list.Add(nestedItem); OnPropertyModified?.Invoke(fieldName, nestedItem); var addNewItem = AddNewListItem(nestedItem, list, rootFieldGroupCard, fieldName); rootFieldGroupCard.ControlsWrapPanel.Children.Add(addNewItem); }; rootFieldGroupCard.DisplayNameTextBlock.Text = displayName; foreach (var item in list) { var addNewItem = AddNewListItem(item, list, rootFieldGroupCard, fieldName); rootFieldGroupCard.ControlsWrapPanel.Children.Add(addNewItem); } userControls.Add(rootFieldGroupCard); }); return(userControls); }