Beispiel #1
0
        private FrameworkElement CreateBindableComboBoxControl(PropertyItem pi, string lookupKey)
        {
            var cbx = new ComboBox();

            var itemsSourceBinding = pi.CreateOneWayBinding();

            itemsSourceBinding.Path   = null;
            itemsSourceBinding.Source = pi.ItemsSource;
            cbx.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);

            ReferenceLookupList.RegisterListUpdateEventHandler(lookupKey, (sender, args) =>
            {
                var list = ReferenceLookupList.GetCompleteList(lookupKey);
                var itemsSourceBinding1    = pi.CreateOneWayBinding();
                itemsSourceBinding1.Path   = null;
                itemsSourceBinding1.Source = list;
                cbx.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding1);
            });

            var selectedItemBinding = pi.CreateBinding();

            selectedItemBinding.Mode = BindingMode.TwoWay;
            //selectedItemBinding.Path = new PropertyPath("Selected");
            cbx.SetBinding(Selector.SelectedItemProperty, selectedItemBinding);

            return(cbx);
        }
 /// <summary>
 /// Creates a control based on a template from a a <see cref="TypeEditor" />.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="editor">The editor.</param>
 /// <returns>
 /// A <see cref="ContentControl" />.
 /// </returns>
 protected virtual ContentControl CreateEditorControl(PropertyItem property, TypeEditor editor)
 {
     var c = new ContentControl
     {
         ContentTemplate = editor.EditorTemplate,
         VerticalAlignment = VerticalAlignment.Center,
         HorizontalAlignment = HorizontalAlignment.Left
     };
     c.SetBinding(FrameworkElement.DataContextProperty, property.CreateOneWayBinding());
     return c;
 }
 /// <summary>
 /// Creates the image control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns>
 /// The control.
 /// </returns>
 protected virtual FrameworkElement CreateImageControl(PropertyItem property)
 {
     var c = new Image { Stretch = Stretch.Uniform, HorizontalAlignment = HorizontalAlignment.Left };
     c.SetBinding(Image.SourceProperty, property.CreateOneWayBinding());
     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);
        }