Beispiel #1
0
        internal static FrameworkElement GetCustomEditor(PropertyItem propertyItem, EditorDefinitionCollection customTypeEditors)
        {
            FrameworkElement editor = null;

            //check for custom editor
            if (customTypeEditors.Count > 0)
            {
                //first check if the custom editor is type based
                EditorDefinition customEditor = customTypeEditors[propertyItem.PropertyType];
                if (customEditor == null)
                {
                    //must be property based
                    customEditor = customTypeEditors[propertyItem.Name];
                }

                if (customEditor != null)
                {
                    if (customEditor.EditorTemplate != null)
                    {
                        editor = customEditor.EditorTemplate.LoadContent() as FrameworkElement;
                    }
                }
            }

            return(editor);
        }
Beispiel #2
0
        internal static FrameworkElement GetCustomEditor(PropertyItem propertyItem, EditorDefinitionCollection customTypeEditors)
        {
            FrameworkElement editor = null;

            //check for custom editor
            if (customTypeEditors.Count > 0)
            {
                //first check if the custom editor is type based
                EditorDefinition customEditor = customTypeEditors[propertyItem.PropertyType];
                if (customEditor == null)
                {
                    //must be property based
                    customEditor = customTypeEditors[propertyItem.Name];
                }

                if (customEditor != null)
                {
                    if (customEditor.EditorTemplate != null)
                    {
                        editor = customEditor.EditorTemplate.LoadContent() as FrameworkElement;
                    }
                }
            }

            var propertyEditAttribute = (from attribute in propertyItem.PropertyDescriptor.Attributes.OfType <PropertyEditorAttribute>()
                                         select attribute).SingleOrDefault();

            if (propertyEditAttribute != null)
            {
                var typeEditor = Activator.CreateInstance(propertyEditAttribute.EditorType) as ITypeEditor;

                editor = typeEditor.ResolveEditor(propertyItem);
            }

            return(editor);
        }