public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { XPathNavigator navigator; IXPathNavigator view = value as IXPathNavigator; if (view != null) { navigator = view.XPathNavigator; } else { navigator = value as XPathNavigator; } if (navigator == null) { return(null); } if (!navigator.HasAttributes) { return(null); } List <XPathNavigator> attributes = new List <XPathNavigator>(); // clone the node's navigator (cursor), so it doesn't lose it's position XPathNavigator attributeNavigator = navigator.Clone(); if (attributeNavigator.MoveToFirstAttribute()) { do { attributes.Add(attributeNavigator.Clone()); }while (attributeNavigator.MoveToNextAttribute()); } return(attributes); }
public override System.Windows.DataTemplate SelectTemplate(object item, DependencyObject container) { IXPathNavigator view = item as IXPathNavigator; if (view != null) { XPathNavigator navigator = view.XPathNavigator; var presenter = container as FrameworkElement; if (navigator != null && presenter != null) { switch (navigator.NodeType) { case XPathNodeType.Root: return(presenter.FindResource("elementXPathNavigatorTemplate") as DataTemplate); //xmlDeclarationXmlNodeTemplate case XPathNodeType.ProcessingInstruction: return(presenter.FindResource("processingInstructionXPathNavigatorTemplate") as DataTemplate); case XPathNodeType.Comment: return(presenter.FindResource("commentXPathNavigatorTemplate") as DataTemplate); case XPathNodeType.Element: return(presenter.FindResource("elementXPathNavigatorTemplate") as DataTemplate); case XPathNodeType.Text: return(presenter.FindResource("textXPathNavigatorTemplate") as DataTemplate); case XPathNodeType.Attribute: return(presenter.FindResource("attributeXPathNavigatorTemplate") as DataTemplate); } } } return(base.SelectTemplate(item, container)); }