// Based on Windows UI Library // Copyright(c) Microsoft Corporation.All rights reserved. // ReSharper disable once CheckNamespace namespace WPFluent.Controls; /// /// Defines the template parts for the control /// [TemplatePart(Name = TemplateElementNavigationViewContentPresenter, Type = typeof(NavigationViewContentPresenter) )] [TemplatePart(Name = TemplateElementMenuItemsItemsControl, Type = typeof(System.Windows.Controls.ItemsControl) )] [TemplatePart(Name = TemplateElementFooterMenuItemsItemsControl, Type = typeof(System.Windows.Controls.ItemsControl) )] [TemplatePart(Name = TemplateElementBackButton, Type = typeof(System.Windows.Controls.Button))] [TemplatePart(Name = TemplateElementToggleButton, Type = typeof(System.Windows.Controls.Button))] [TemplatePart(Name = TemplateElementAutoSuggestBoxSymbolButton, Type = typeof(System.Windows.Controls.Button) )] public partial class NavigationView { /// /// Template element represented by the PART_AutoSuggestBoxSymbolButton name. /// private const string TemplateElementAutoSuggestBoxSymbolButton = "PART_AutoSuggestBoxSymbolButton"; /// /// Template element represented by the PART_BackButton name. /// private const string TemplateElementBackButton = "PART_BackButton"; /// /// Template element represented by the PART_FooterMenuItemsItemsControl name. /// private const string TemplateElementFooterMenuItemsItemsControl = "PART_FooterMenuItemsItemsControl"; /// /// Template element represented by the PART_MenuItemsItemsControl name. /// private const string TemplateElementMenuItemsItemsControl = "PART_MenuItemsItemsControl"; /// /// Template element represented by the PART_MenuItemsItemsControl name. /// private const string TemplateElementNavigationViewContentPresenter = "PART_NavigationViewContentPresenter"; /// /// Template element represented by the PART_ToggleButton name. /// private const string TemplateElementToggleButton = "PART_ToggleButton"; protected T GetTemplateChild(string name) where T : DependencyObject { if(GetTemplateChild(name) is not T dependencyObject) { throw new ArgumentNullException(name); } return dependencyObject; } /// /// Gets or sets the control that is visitable if PaneDisplayMode="Left" and in compact state /// protected System.Windows.Controls.Button? AutoSuggestBoxSymbolButton { get; set; } /// /// Gets or sets the control located at the top of the pane with left arrow icon. /// protected System.Windows.Controls.Button? BackButton { get; set; } /// /// Gets or sets the control located at the top of the pane with hamburger icon. /// protected System.Windows.Controls.ItemsControl FooterMenuItemsItemsControl { get; set; } = null!; /// /// Gets or sets the control located at the top of the pane with left arrow icon. /// protected System.Windows.Controls.ItemsControl MenuItemsItemsControl { get; set; } = null!; /// /// Gets or sets the control responsible for rendering the content. /// protected NavigationViewContentPresenter NavigationViewContentPresenter { get; set; } = null!; /// /// Gets or sets the control located at the top of the pane with hamburger icon. /// protected System.Windows.Controls.Button? ToggleButton { get; set; } /// public override void OnApplyTemplate() { base.OnApplyTemplate(); NavigationViewContentPresenter = GetTemplateChild( TemplateElementNavigationViewContentPresenter); MenuItemsItemsControl = GetTemplateChild( TemplateElementMenuItemsItemsControl); FooterMenuItemsItemsControl = GetTemplateChild( TemplateElementFooterMenuItemsItemsControl); MenuItemsItemsControl.SetCurrentValue(System.Windows.Controls.ItemsControl.ItemsSourceProperty, MenuItems); FooterMenuItemsItemsControl.SetCurrentValue( System.Windows.Controls.ItemsControl.ItemsSourceProperty, FooterMenuItems); if(NavigationViewContentPresenter is not null) { NavigationViewContentPresenter.Navigated -= OnNavigationViewContentPresenterNavigated; NavigationViewContentPresenter.Navigated += OnNavigationViewContentPresenterNavigated; } if(GetTemplateChild(TemplateElementAutoSuggestBoxSymbolButton) is System.Windows.Controls.Button autoSuggestBoxSymbolButton) { AutoSuggestBoxSymbolButton = autoSuggestBoxSymbolButton; AutoSuggestBoxSymbolButton.Click -= AutoSuggestBoxSymbolButtonOnClick; AutoSuggestBoxSymbolButton.Click += AutoSuggestBoxSymbolButtonOnClick; } if(GetTemplateChild(TemplateElementBackButton) is System.Windows.Controls.Button backButton) { BackButton = backButton; BackButton.Click -= OnBackButtonClick; BackButton.Click += OnBackButtonClick; } if(GetTemplateChild(TemplateElementToggleButton) is System.Windows.Controls.Button toggleButton) { ToggleButton = toggleButton; ToggleButton.Click -= OnToggleButtonClick; ToggleButton.Click += OnToggleButtonClick; } } }