예제 #1
0
        /// <summary>
        /// Selects a DataTemplate appropriate for a PropertyNode</summary>
        /// <param name="item">Item (PropertyNode) to select editor for</param>
        /// <param name="container">Item's container (not used)</param>
        /// <returns>DataTemplate appropriate for the PropertyNode</returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var node = item as PropertyNode;

            if (node != null)
            {
                // Try and get custom editor from the node
                ValueEditor customEditor = node.GetCustomEditor();
                if (customEditor != null)
                {
                    if (customEditor.UsesCustomContext && node.EditorContext == null)
                    {
                        node.EditorContext = customEditor.GetCustomContext(node);
                    }
                    else if (!customEditor.UsesCustomContext)
                    {
                        node.EditorContext = null;
                    }

                    if (SelectNonEditingTemplates)
                    {
                        return(customEditor.GetNonEditingTemplate(node, container));
                    }
                    return(customEditor.GetTemplate(node, container));
                }

                // If this fails, try to get an editor from the editors list
                if (Editors != null)
                {
                    foreach (ValueEditor editor in Editors)
                    {
                        if (editor.CanEdit(node))
                        {
                            if (SelectNonEditingTemplates)
                            {
                                return(editor.GetNonEditingTemplate(node, container));
                            }

                            if (editor.UsesCustomContext && node.EditorContext == null)
                            {
                                node.EditorContext = editor.GetCustomContext(node);
                            }
                            else if (!editor.UsesCustomContext)
                            {
                                node.EditorContext = null;
                            }

                            return(editor.GetTemplate(node, container));
                        }
                    }
                }

                // If this fails then use a default template
                return(GetDefaultTemplate(node, container));
            }

            return(new DataTemplate());
        }
예제 #2
0
        /// <summary>
        /// Selects a DataTemplate appropriate for a PropertyNode</summary>
        /// <param name="item">Item (PropertyNode) to select editor for</param>
        /// <param name="container">Item's container (not used)</param>
        /// <returns>DataTemplate appropriate for the PropertyNode</returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var node = item as PropertyNode;

            if (node != null)
            {
                // Try and get custom editor from the node
                ValueEditor customEditor = node.GetCustomEditor();
                if (customEditor != null)
                {
                    if (customEditor.UsesCustomContext && node.EditorContext == null)
                    {
                        node.EditorContext = customEditor.GetCustomContext(node);
                    }
                    else if (!customEditor.UsesCustomContext)
                    {
                        node.EditorContext = null;
                    }

                    return(customEditor.GetTemplate(node));
                }

                // If this fails, try to get an editor from the editors list
                if (Editors != null)
                {
                    // TODO: need to guard against editors being changed mid-enumeration
                    foreach (ValueEditor editor in Editors)
                    {
                        if (editor.CanEdit(node))
                        {
                            return(editor.GetTemplate(node));
                        }
                    }
                }

                // If this fails then use a default template
                return(GetDefaultTemplate(node));
            }

            return(null);
        }
예제 #3
0
 public void SetCustomEditor(ValueEditor valueEditor)
 {
     mValueEditor = valueEditor;
 }