using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Markup; namespace MaterialDesignThemes.Wpf { public static class TreeViewAssist { /// /// Allows additional rendering for each tree node, outside of the rippled part of the node which responsds to user selection. /// /// /// The content to be rendered is the same of the ; i.e the Header property, or /// some other content such as a view model, typically when using a . /// public static readonly DependencyProperty AdditionalTemplateProperty = DependencyProperty.RegisterAttached( "AdditionalTemplate", typeof(DataTemplate), typeof(TreeViewAssist), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); /// /// Sets the additional template. /// /// The element. /// The value. public static void SetAdditionalTemplate(DependencyObject element, DataTemplate value) { element.SetValue(AdditionalTemplateProperty, value); } /// /// Gets the additional template. /// /// The element. /// /// The . /// public static DataTemplate GetAdditionalTemplate(DependencyObject element) { return (DataTemplate)element.GetValue(AdditionalTemplateProperty); } /// /// Allows additional rendering for each tree node, outside of the rippled part of the node which responsds to user selection. /// /// /// The content to be rendered is the same of the ; i.e the Header property, or /// some other content such as a view model, typically when using a . /// public static readonly DependencyProperty AdditionalTemplateSelectorProperty = DependencyProperty.RegisterAttached( "AdditionalTemplateSelector", typeof(DataTemplateSelector), typeof(TreeViewAssist), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); /// /// Sets the additional template selector. /// /// The element. /// The value. public static void SetAdditionalTemplateSelector(DependencyObject element, DataTemplateSelector value) { element.SetValue(AdditionalTemplateSelectorProperty, value); } /// /// Gets the additional template selector. /// /// The element. /// /// The . /// public static DataTemplateSelector GetAdditionalTemplateSelector(DependencyObject element) { return (DataTemplateSelector)element.GetValue(AdditionalTemplateSelectorProperty); } private static readonly Lazy NoAdditionalTemplateProvider = new Lazy(CreateEmptyGridDataTemplate); /// /// To be used at level, or to be returned by /// implementors when the additional template associated with a tree should not be used. /// public static readonly DataTemplate SuppressAdditionalTemplate = NoAdditionalTemplateProvider.Value; public static DataTemplate CreateEmptyGridDataTemplate() { var xaml = ""; var parserContext = new ParserContext(); parserContext.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); parserContext.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml"); using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(xaml))) { return (DataTemplate)XamlReader.Load(memoryStream, parserContext); } } } }