using System.Windows; using System.Windows.Controls; using VersOne.Epub.WpfDemo.ViewModels; namespace VersOne.Epub.WpfDemo.Controls { /// /// A data template selector class that chooses between the and templates /// based on the type of the navigation item. /// public class NavigationTemplateSelector : DataTemplateSelector { /// /// Gets or sets the data template to render a navigation header. /// public DataTemplate NavigationHeaderTemplate { get; set; } /// /// Gets or sets the data template to render a navigation link. /// public DataTemplate NavigationItemTemplate { get; set; } /// /// Returns the if the is a navigation link and otherwise. /// /// The navigation item for which to select the template. /// The data-bound object. Not used in this template selector. /// The selected data template. public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (item is NavigationItemViewModel navigationItemViewModel) { return navigationItemViewModel.IsLink ? NavigationItemTemplate : NavigationHeaderTemplate; } else { return null; } } } }