public override void OnApplyTemplate() { // Stop UpdateVisualState before template is applied. Otherwise the visual may not the same as we expect m_appliedTemplate = false; base.OnApplyTemplate(); // Find selection indicator // Retrieve pointers to stable controls IControlProtected controlProtected = this; m_helper.Init(controlProtected); if (GetTemplateChildT <Grid>(c_rootGrid, controlProtected) is { } rootGrid) { m_rootGrid = rootGrid; if (FlyoutBase.GetAttachedFlyout(rootGrid) is { } flyoutBase) { flyoutBase.Closing += OnFlyoutClosing; } } if (GetTemplateChildT <NavigationViewItemPresenter>(c_navigationViewItemPresenterName, controlProtected) is { } presenter) { m_navigationViewItemPresenter = presenter; presenter.MouseDown += OnPresenterPointerPressed; presenter.MouseUp += OnPresenterPointerReleased; presenter.MouseEnter += OnPresenterPointerEntered; presenter.MouseLeave += OnPresenterPointerCanceled; presenter.LostMouseCapture += OnPresenterPointerCaptureLost; }
public static WinRTReturn GetTemplateChildT <WinRTReturn>(string childName, IControlProtected controlProtected) where WinRTReturn : DependencyObject { DependencyObject childAsDO = controlProtected.GetTemplateChild(childName); if (childAsDO != null) { return(childAsDO as WinRTReturn); } return(null); }
public override void OnApplyTemplate() { // Stop UpdateVisualState before template is applied. Otherwise the visual may not the same as we expect m_appliedTemplate = false; base.OnApplyTemplate(); // Find selection indicator // Retrieve pointers to stable controls IControlProtected controlProtected = this; m_helper.Init(controlProtected); if (GetTemplateChildT <Grid>(c_rootGrid, controlProtected) is { } rootGrid) { m_rootGrid = rootGrid; if (FlyoutBase.GetAttachedFlyout(rootGrid) is { } flyoutBase) { flyoutBase.Closing += OnFlyoutClosing; } } UIElement presenter; { presenter = init(); UIElement init() { if (GetTemplateChildT <NavigationViewItemPresenter>(c_navigationViewItemPresenterName, controlProtected) is { } presenter) { m_navigationViewItemPresenter = presenter; return(presenter); } // We don't have a presenter, so we are our own presenter. return(this); } } presenter.MouseDown += OnPresenterPointerPressed; presenter.MouseUp += OnPresenterPointerReleased; presenter.MouseEnter += OnPresenterPointerEntered; presenter.MouseLeave += OnPresenterPointerCanceled; presenter.LostMouseCapture += OnPresenterPointerCaptureLost; m_toolTip = GetTemplateChildT <ToolTip>("ToolTip", controlProtected); if (GetSplitView() is { } splitView) { splitView.IsPaneOpenChanged += OnSplitViewPropertyChanged; splitView.DisplayModeChanged += OnSplitViewPropertyChanged; splitView.CompactPaneLengthChanged += OnSplitViewPropertyChanged; UpdateCompactPaneLength(); UpdateIsClosedCompact(); } // Retrieve reference to NavigationView if (GetNavigationView() is { } nvImpl) { if (GetTemplateChildT <ItemsRepeater>(c_repeater, controlProtected) is { } repeater) { m_repeater = repeater; // Primary element setup happens in NavigationView repeater.ElementPrepared += nvImpl.OnRepeaterElementPrepared; repeater.ElementClearing += nvImpl.OnRepeaterElementClearing; repeater.ItemTemplate = nvImpl.GetNavigationViewItemsFactory(); repeater.AlwaysInvalidateMeasureOnChildDesiredSizeChanged = true; } UpdateRepeaterItemsSource(); } if (GetTemplateChildT <FlyoutBase>(c_childrenFlyout, controlProtected) is { } childrenFlyout) { childrenFlyout.Offset = 0; } m_flyoutContentGrid = GetTemplateChildT <Grid>(c_flyoutContentGrid, controlProtected); m_appliedTemplate = true; UpdateItemIndentation(); UpdateVisualStateNoTransition(); ReparentRepeater(); // We dont want to update the repeater visibilty during OnApplyTemplate if NavigationView is in a mode when items are shown in a flyout if (!ShouldRepeaterShowInFlyout()) { ShowHideChildren(); } /* * var visual = ElementCompositionPreview.GetElementVisual(this); * NavigationView.CreateAndAttachHeaderAnimation(visual); */ }
public override void OnApplyTemplate() { // Stop UpdateVisualState before template is applied. Otherwise the visuals may be unexpected m_appliedTemplate = false; UnhookEventsAndClearFields(); base.OnApplyTemplate(); // Find selection indicator // Retrieve pointers to stable controls IControlProtected controlProtected = this; m_helper.Init(controlProtected); if (GetTemplateChildT <Grid>(c_rootGrid, controlProtected) is { } rootGrid) { m_rootGrid = rootGrid; if (FlyoutBase.GetAttachedFlyout(rootGrid) is { } flyoutBase) { m_flyoutClosingRevoker = new FlyoutBaseClosingRevoker(flyoutBase, OnFlyoutClosing); } } HookInputEvents(controlProtected); IsEnabledChanged += OnIsEnabledChanged; m_toolTip = GetTemplateChildT <ToolTip>("ToolTip", controlProtected); if (GetSplitView() is { } splitView) { splitView.IsPaneOpenChanged += OnSplitViewPropertyChanged; splitView.DisplayModeChanged += OnSplitViewPropertyChanged; splitView.CompactPaneLengthChanged += OnSplitViewPropertyChanged; UpdateCompactPaneLength(); UpdateIsClosedCompact(); } // Retrieve reference to NavigationView if (GetNavigationView() is { } nvImpl) { if (GetTemplateChildT <ItemsRepeater>(c_repeater, controlProtected) is { } repeater) { m_repeater = repeater; // Primary element setup happens in NavigationView m_repeaterElementPreparedRevoker = new ItemsRepeaterElementPreparedRevoker(repeater, nvImpl.OnRepeaterElementPrepared); m_repeaterElementClearingRevoker = new ItemsRepeaterElementClearingRevoker(repeater, nvImpl.OnRepeaterElementClearing); repeater.ItemTemplate = nvImpl.GetNavigationViewItemsFactory(); repeater.AlwaysInvalidateMeasureOnChildDesiredSizeChanged = true; } UpdateRepeaterItemsSource(); } if (GetTemplateChildT <FlyoutBase>(c_childrenFlyout, controlProtected) is { } childrenFlyout) { childrenFlyout.Offset = 0; } m_flyoutContentGrid = GetTemplateChildT <Grid>(c_flyoutContentGrid, controlProtected); m_appliedTemplate = true; UpdateItemIndentation(); UpdateVisualStateNoTransition(); ReparentRepeater(); // We dont want to update the repeater visibilty during OnApplyTemplate if NavigationView is in a mode when items are shown in a flyout if (!ShouldRepeaterShowInFlyout()) { ShowHideChildren(); } /* * var visual = ElementCompositionPreview.GetElementVisual(this); * NavigationView.CreateAndAttachHeaderAnimation(visual); */ }