protected virtual FrameworkElement CreateComboBox(PropertyItem pi, PropertyControlFactoryOptions options)
 {
     var cbox = new ComboBox() { IsEditable = true };
     cbox.SetBinding(Selector.SelectedItemProperty, new Binding(pi.Descriptor.Name + ".Text"));
     cbox.SetBinding(ItemsControl.ItemsSourceProperty, new Binding(pi.Descriptor.Name + ".Values"));
     return cbox;
 }
Esempio n. 2
0
 public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options)
 {
     if (pi.Is(typeof(IValueWithSource)))
     {
         return CreateComboBox(pi, options);
     }
     return base.CreateControl(pi, options);
 }
        public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options)
        {
            // Check if the property is of type Range
            if (pi.Is(typeof(IValueWithSource)))
            {
                // Create a control to edit the Range
                return this.CreateComboBox(pi, options);
            }

            return base.CreateControl(pi, options);
        }
        public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options)
        {
            //if (property.Is(typeof(DateTime)))
            //{
            //    var dp = new DatePicker() { SelectedDateFormat = DatePickerFormat.Long, DisplayDateStart = DateTime.Now.AddDays(-7) };
            //    dp.SetBinding(DatePicker.SelectedDateProperty,
            //        new Binding(property.Descriptor.Name) { ValidatesOnDataErrors = true });
            //    return dp;
            //}

            return base.CreateControl(pi, options);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the select control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateEnumControl(
            PropertyItem property, PropertyControlFactoryOptions options)
        {
            // TODO: use check boxes for bit fields
            //// var isBitField = property.Descriptor.PropertyType.GetTypeInfo().GetCustomAttributes<FlagsAttribute>().Any();

            var values = this.GetEnumValues(property.Descriptor.PropertyType).ToArray();
            var style  = property.SelectorStyle;

            if (style == DataAnnotations.SelectorStyle.Auto)
            {
                style = values.Length > options.EnumAsRadioButtonsLimit
                            ? DataAnnotations.SelectorStyle.ComboBox
                            : DataAnnotations.SelectorStyle.RadioButtons;
            }

            switch (style)
            {
            case DataAnnotations.SelectorStyle.RadioButtons:
            {
                var c = new RadioButtonList {
                    EnumType = property.Descriptor.PropertyType
                };
                c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
                return(c);
            }

            case DataAnnotations.SelectorStyle.ComboBox:
            {
                var c = new ComboBox {
                    ItemsSource = values
                };
                c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                return(c);
            }

            case DataAnnotations.SelectorStyle.ListBox:
            {
                var c = new ListBox {
                    ItemsSource = values
                };
                c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                return(c);
            }

            default:
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Creates the select control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateEnumControl(
            PropertyItem property, PropertyControlFactoryOptions options)
        {
            var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);
            var values   = Enum.GetValues(enumType);
            var style    = property.SelectorStyle;

            if (style == DataAnnotations.SelectorStyle.Auto)
            {
                style = values.Length > options.EnumAsRadioButtonsLimit
                            ? DataAnnotations.SelectorStyle.ComboBox
                            : DataAnnotations.SelectorStyle.RadioButtons;
            }

            switch (style)
            {
            case DataAnnotations.SelectorStyle.RadioButtons:
            {
                var c = new RadioButtonList {
                    EnumType = property.Descriptor.PropertyType
                };
                c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
                return(c);
            }

            case DataAnnotations.SelectorStyle.ComboBox:
            {
                var c = new ComboBox {
                    ItemsSource = Enum.GetValues(enumType)
                };
                c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                return(c);
            }

            case DataAnnotations.SelectorStyle.ListBox:
            {
                var c = new ListBox {
                    ItemsSource = Enum.GetValues(enumType)
                };
                c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                return(c);
            }

            default:
                return(null);
            }
        }
        protected virtual FrameworkElement CreateRangeControl(PropertyItem pi, PropertyControlFactoryOptions options)
        {
            var grid = new Grid();
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            var minimumBox = new TextBox();
            minimumBox.SetBinding(TextBox.TextProperty, new Binding(pi.Descriptor.Name + ".Minimum"));
            var label = new Label { Content = "-" };
            Grid.SetColumn(label, 1);
            var maximumBox = new TextBox();
            Grid.SetColumn(maximumBox, 2);
            maximumBox.SetBinding(TextBox.TextProperty, new Binding(pi.Descriptor.Name + ".Maximum"));
            grid.Children.Add(minimumBox);
            grid.Children.Add(label);
            grid.Children.Add(maximumBox);

            if (pi is ImportantPropertyItem)
            {
                minimumBox.Background = maximumBox.Background = Brushes.Yellow;
            }

            return grid;
        }
Esempio n. 8
0
        /// <summary>
        /// Creates the property control.
        /// </summary>
        /// <param name="pi">The property item.</param>
        /// <returns>
        /// An element.
        /// </returns>
        private FrameworkElement CreatePropertyControl(PropertyItem pi)
        {
            var options = new PropertyControlFactoryOptions { EnumAsRadioButtonsLimit = this.EnumAsRadioButtonsLimit };
            var control = this.PropertyControlFactory.CreateControl(pi, options);
            if (control != null)
            {
                control.SetValue(AutomationProperties.AutomationIdProperty, pi.PropertyName);
            }

            return control;
        }
        /// <summary>
        /// Creates the control for a property.
        /// </summary>
        /// <param name="property">
        /// The property item.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// A element.
        /// </returns>
        public virtual FrameworkElement CreateControl(PropertyItem property, PropertyControlFactoryOptions options)
        {
            this.UpdateConverter(property);

            foreach (var editor in this.Editors)
            {
                if (editor.IsAssignable(property.Descriptor.PropertyType))
                {
                    var c = new ContentControl
                    {
                        ContentTemplate     = editor.EditorTemplate,
                        VerticalAlignment   = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Left
                    };
                    c.SetBinding(FrameworkElement.DataContextProperty, property.CreateOneWayBinding());
                    return(c);
                }
            }

            if (property.Is(typeof(bool)))
            {
                return(this.CreateBoolControl(property));
            }

            if (property.Is(typeof(Enum)))
            {
                return(this.CreateEnumControl(property, options));
            }

            if (property.Is(typeof(Color)))
            {
                return(this.CreateColorControl(property));
            }

            if (property.Is(typeof(Brush)))
            {
                return(this.CreateBrushControl(property));
            }

            if (property.Is(typeof(FontFamily)))
            {
                return(this.CreateFontFamilyControl(property));
            }

            if (property.Is(typeof(ImageSource)) || property.DataTypes.Contains(DataType.ImageUrl))
            {
                return(this.CreateImageControl(property));
            }

            if (property.DataTypes.Contains(DataType.Html))
            {
                return(this.CreateHtmlControl(property));
            }

            if (property.Is(typeof(Uri)))
            {
                return(this.CreateLinkControl(property));
            }

            if (property.ItemsSourceDescriptor != null)
            {
                return(this.CreateComboBoxControl(property));
            }

            if (property.Is(typeof(SecureString)))
            {
                return(this.CreateSecurePasswordControl(property));
            }

            if (this.UseDatePicker && property.Is(typeof(DateTime)))
            {
                return(this.CreateDateTimeControl(property));
            }

            if (property.IsFilePath)
            {
                return(this.CreateFilePathControl(property));
            }

            if (property.IsDirectoryPath)
            {
                return(this.CreateDirectoryPathControl(property));
            }

            if (property.PreviewFonts)
            {
                return(this.CreateFontPreview(property));
            }

            if (property.IsComment)
            {
                return(this.CreateCommentControl(property));
            }

            if (property.IsPassword)
            {
                return(this.CreatePasswordControl(property));
            }

            if (property.IsSlidable)
            {
                return(this.CreateSliderControl(property));
            }

            if (property.IsSpinnable)
            {
                return(this.CreateSpinControl(property));
            }

            if (property.Is(typeof(IList)))
            {
                return(this.CreateGridControl(property));
            }

            if (property.Is(typeof(IDictionary)))
            {
                return(this.CreateDictionaryControl(property));
            }

            return(this.CreateDefaultControl(property));
        }
Esempio n. 10
0
        /// <summary>
        /// Creates the control for a property.
        /// </summary>
        /// <param name="property">The property item.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// A element.
        /// </returns>
        public virtual FrameworkElement CreateControl(PropertyItem property, PropertyControlFactoryOptions options)
        {
            this.UpdateConverter(property);

            foreach (var editor in this.Editors)
            {
                if (editor.IsAssignable(property.Descriptor.PropertyType))
                {
                    return(this.CreateEditorControl(property, editor));
                }
            }

            if (property.Is(typeof(bool)))
            {
                return(this.CreateBoolControl(property));
            }

            if (property.Is(typeof(Enum)))
            {
                return(this.CreateEnumControl(property, options));
            }

            if (property.Is(typeof(Color)))
            {
                return(this.CreateColorControl(property));
            }

            if (property.Is(typeof(Brush)))
            {
                return(this.CreateBrushControl(property));
            }

            if (property.Is(typeof(FontFamily)) || property.IsFontFamilySelector)
            {
                return(this.CreateFontFamilyControl(property));
            }

            if (property.Is(typeof(ImageSource)) || property.DataTypes.Contains(DataType.ImageUrl))
            {
                return(this.CreateImageControl(property));
            }

            if (property.DataTypes.Contains(DataType.Html))
            {
                return(this.CreateHtmlControl(property));
            }

            if (property.Is(typeof(Uri)))
            {
                return(this.CreateLinkControl(property));
            }

            if (property.ItemsSourceDescriptor != null || property.ItemsSource != null)
            {
                return(this.CreateComboBoxControl(property));
            }

            if (property.Is(typeof(SecureString)))
            {
                return(this.CreateSecurePasswordControl(property));
            }

            if (this.UseDatePicker && property.Is(typeof(DateTime)))
            {
                return(this.CreateDateTimeControl(property));
            }

            if (property.IsFilePath)
            {
                return(this.CreateFilePathControl(property));
            }

            if (property.IsDirectoryPath)
            {
                return(this.CreateDirectoryPathControl(property));
            }

            if (property.PreviewFonts)
            {
                return(this.CreateFontPreview(property));
            }

            if (property.IsComment)
            {
                return(this.CreateCommentControl(property));
            }

            if (property.IsContent)
            {
                return(this.CreateContentControl(property));
            }

            if (property.IsPassword)
            {
                return(this.CreatePasswordControl(property));
            }

            if (property.IsSlidable)
            {
                return(this.CreateSliderControl(property));
            }

            if (property.IsSpinnable)
            {
                return(this.CreateSpinControl(property));
            }

            if (property.CheckableItemsIsCheckedPropertyName != null)
            {
                return(this.CreateCheckableItems(property));
            }

            if (property.Is(typeof(IDictionary)) || property.Is(typeof(IDictionary <,>)))
            {
                return(this.CreateDictionaryControl(property));
            }

            if (property.Is(typeof(ICollection)) || property.Is(typeof(ICollection <>)))
            {
                return(this.CreateGridControl(property));
            }

            return(this.CreateDefaultControl(property));
        }
Esempio n. 11
0
        /// <summary>
        /// Creates the error control.
        /// </summary>
        public virtual ContentControl CreateErrorControl(PropertyItem pi, object instance, Tab tab, PropertyControlFactoryOptions options)
        {
            var dataErrorInfoInstance       = instance as IDataErrorInfo;
            var notifyDataErrorInfoInstance = instance as INotifyDataErrorInfo;

            var errorControl = new ContentControl
            {
                ContentTemplate = options.ValidationErrorTemplate,
                Focusable       = false
            };
            IValueConverter errorConverter;
            string          propertyPath;
            object          source = null;

            if (dataErrorInfoInstance != null)
            {
                errorConverter = new DataErrorInfoConverter(dataErrorInfoInstance, pi.PropertyName);
                propertyPath   = pi.PropertyName;
                source         = instance;
            }
            else
            {
                errorConverter = new NotifyDataErrorInfoConverter(notifyDataErrorInfoInstance, pi.PropertyName);
                propertyPath   = nameof(tab.HasErrors);
                source         = tab;
                notifyDataErrorInfoInstance.ErrorsChanged += (s, e) =>
                {
                    tab.UpdateHasErrors(notifyDataErrorInfoInstance);
                };
            }

            var visibilityBinding = new Binding(propertyPath)
            {
                Converter             = errorConverter,
                NotifyOnTargetUpdated = true,
#if !NET40
                ValidatesOnNotifyDataErrors = false,
#endif
                Source = source,
            };

            var contentBinding = new Binding(propertyPath)
            {
                Converter = errorConverter,
#if !NET40
                ValidatesOnNotifyDataErrors = false,
#endif
                Source = source,
            };

            errorControl.SetBinding(UIElement.VisibilityProperty, visibilityBinding);

            // When the visibility of the error control is changed, updated the HasErrors of the tab
            errorControl.TargetUpdated += (s, e) =>
            {
                if (dataErrorInfoInstance != null)
                {
                    tab.UpdateHasErrors(dataErrorInfoInstance);
                }
            };
            errorControl.SetBinding(ContentControl.ContentProperty, contentBinding);
            return(errorControl);
        }
Esempio n. 12
0
 /// <summary>
 /// Creates the property control.
 /// </summary>
 /// <param name="pi">
 /// The property item.
 /// </param>
 /// <returns>
 /// An element.
 /// </returns>
 private FrameworkElement CreatePropertyControl(PropertyItem pi)
 {
     var options = new PropertyControlFactoryOptions { EnumAsRadioButtonsLimit = this.EnumAsRadioButtonsLimit };
     return this.PropertyControlFactory.CreateControl(pi, options);
 }
        /// <summary>
        /// Creates the select control.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// The control.
        /// </returns>
        protected virtual FrameworkElement CreateEnumControl(
            PropertyItem property, PropertyControlFactoryOptions options)
        {
            var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);
            var values = Enum.GetValues(enumType);
            var style = property.SelectorStyle;
            if (style == DataAnnotations.SelectorStyle.Auto)
            {
                style = values.Length > options.EnumAsRadioButtonsLimit
                            ? DataAnnotations.SelectorStyle.ComboBox
                            : DataAnnotations.SelectorStyle.RadioButtons;
            }

            switch (style)
            {
                case DataAnnotations.SelectorStyle.RadioButtons:
                    {
                        var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType };
                        c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
                        return c;
                    }

                case DataAnnotations.SelectorStyle.ComboBox:
                    {
                        var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) };
                        c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                        return c;
                    }

                case DataAnnotations.SelectorStyle.ListBox:
                    {
                        var c = new ListBox { ItemsSource = Enum.GetValues(enumType) };
                        c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                        return c;
                    }

                default:
                    return null;
            }
        }
        /// <summary>
        /// Creates the control for a property.
        /// </summary>
        /// <param name="property">The property item.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// A element.
        /// </returns>
        public virtual FrameworkElement CreateControl(PropertyItem property, PropertyControlFactoryOptions options)
        {
            this.UpdateConverter(property);

            foreach (var editor in this.Editors)
            {
                if (editor.IsAssignable(property.Descriptor.PropertyType))
                {
                    return this.CreateEditorControl(property, editor);
                }
            }

            if (property.Is(typeof(bool)))
            {
                return this.CreateBoolControl(property);
            }

            if (property.Is(typeof(Enum)))
            {
                return this.CreateEnumControl(property, options);
            }

            if (property.Is(typeof(Color)))
            {
                return this.CreateColorControl(property);
            }

            if (property.Is(typeof(Brush)))
            {
                return this.CreateBrushControl(property);
            }

            if (property.Is(typeof(FontFamily)) || property.IsFontFamilySelector)
            {
                return this.CreateFontFamilyControl(property);
            }

            if (property.Is(typeof(ImageSource)) || property.DataTypes.Contains(DataType.ImageUrl))
            {
                return this.CreateImageControl(property);
            }

            if (property.DataTypes.Contains(DataType.Html))
            {
                return this.CreateHtmlControl(property);
            }

            if (property.Is(typeof(Uri)))
            {
                return this.CreateLinkControl(property);
            }

            if (property.ItemsSourceDescriptor != null || property.ItemsSource != null)
            {
                return this.CreateComboBoxControl(property);
            }

            if (property.Is(typeof(SecureString)))
            {
                return this.CreateSecurePasswordControl(property);
            }

            if (this.UseDatePicker && property.Is(typeof(DateTime)))
            {
                return this.CreateDateTimeControl(property);
            }

            if (property.IsFilePath)
            {
                return this.CreateFilePathControl(property);
            }

            if (property.IsDirectoryPath)
            {
                return this.CreateDirectoryPathControl(property);
            }

            if (property.PreviewFonts)
            {
                return this.CreateFontPreview(property);
            }

            if (property.IsComment)
            {
                return this.CreateCommentControl(property);
            }

            if (property.IsContent)
            {
                return this.CreateContentControl(property);
            }

            if (property.IsPassword)
            {
                return this.CreatePasswordControl(property);
            }

            if (property.IsSlidable)
            {
                return this.CreateSliderControl(property);
            }

            if (property.IsSpinnable)
            {
                return this.CreateSpinControl(property);
            }

            if (property.CheckableItemsIsCheckedPropertyName != null)
            {
                return this.CreateCheckableItems(property);
            }

            if (property.Is(typeof(IDictionary)) || property.Is(typeof(IDictionary<,>)))
            {
                return this.CreateDictionaryControl(property);
            }

            if (property.Is(typeof(ICollection)) || property.Is(typeof(ICollection<>)))
            {
                return this.CreateGridControl(property);
            }

            return this.CreateDefaultControl(property);
        }
        /// <summary>
        /// Creates the enum control.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The control.
        /// </returns>
        protected FrameworkElement CreateEnumControl(PropertyItem property, PropertyControlFactoryOptions options)
        {
            var isRadioButton = true;
            var enumType = TypeHelper.GetEnumType(property.Descriptor.PropertyType);
            var values = Enum.GetValues(enumType);
            if (values.Length > options.EnumAsRadioButtonsLimit && !property.UseRadioButtons)
            {
                isRadioButton = false;
            }

            if (isRadioButton)
            {
                var c = new RadioButtonList { EnumType = property.Descriptor.PropertyType };
                c.SetBinding(RadioButtonList.ValueProperty, property.CreateBinding());
                return c;
            }
            else
            {
                var c = new ComboBox { ItemsSource = Enum.GetValues(enumType) };
                c.SetBinding(Selector.SelectedValueProperty, property.CreateBinding());
                return c;
            }
        }
        /// <summary>
        /// Creates the control for a property.
        /// </summary>
        /// <param name="property">
        /// The property item.
        /// </param>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// A element.
        /// </returns>
        public virtual FrameworkElement CreateControl(PropertyItem property, PropertyControlFactoryOptions options)
        {
            this.UpdateConverter(property);

            foreach (var editor in this.Editors)
            {
                if (editor.IsAssignable(property.Descriptor.PropertyType))
                {
                    var c = new ContentControl
                        {
                            ContentTemplate = editor.EditorTemplate,
                            VerticalAlignment = VerticalAlignment.Center,
                            HorizontalAlignment = HorizontalAlignment.Left
                        };
                    c.SetBinding(FrameworkElement.DataContextProperty, property.CreateOneWayBinding());
                    return c;
                }
            }

            if (property.Is(typeof(bool)))
            {
                return this.CreateBoolControl(property);
            }

            if (property.Is(typeof(Enum)))
            {
                return this.CreateEnumControl(property, options);
            }

            if (property.Is(typeof(Color)))
            {
                return this.CreateColorControl(property);
            }

            if (property.Is(typeof(Brush)))
            {
                return this.CreateBrushControl(property);
            }

            if (property.Is(typeof(FontFamily)))
            {
                return this.CreateFontFamilyControl(property);
            }

            if (property.Is(typeof(ImageSource)) || property.DataTypes.Contains(DataType.ImageUrl))
            {
                return this.CreateImageControl(property);
            }

            if (property.DataTypes.Contains(DataType.Html))
            {
                return this.CreateHtmlControl(property);
            }

            if (property.Is(typeof(Uri)))
            {
                return this.CreateLinkControl(property);
            }

            if (property.ItemsSourceDescriptor != null)
            {
                return this.CreateComboBoxControl(property);
            }

            if (property.Is(typeof(SecureString)))
            {
                return this.CreateSecurePasswordControl(property);
            }

            if (this.UseDatePicker && property.Is(typeof(DateTime)))
            {
                return this.CreateDateTimeControl(property);
            }

            if (property.IsFilePath)
            {
                return this.CreateFilePathControl(property);
            }

            if (property.IsDirectoryPath)
            {
                return this.CreateDirectoryPathControl(property);
            }

            if (property.PreviewFonts)
            {
                return this.CreateFontPreview(property);
            }

            if (property.IsComment)
            {
                return this.CreateCommentControl(property);
            }

            if (property.IsPassword)
            {
                return this.CreatePasswordControl(property);
            }

            if (property.IsSlidable)
            {
                return this.CreateSliderControl(property);
            }

            if (property.IsSpinnable)
            {
                return this.CreateSpinControl(property);
            }

            if (property.Is(typeof(IList)))
            {
                return this.CreateGridControl(property);
            }

            if (property.Is(typeof(IDictionary)))
            {
                return this.CreateDictionaryControl(property);
            }

            return this.CreateDefaultControl(property);
        }