protected override void OnApplyTemplate()
        {
            // TODO: Uno specific: NavigationView may not be set yet, wait for later #4689
            if (GetNavigationView() is null)
            {
                // Postpone template application for later
                return;
            }

            var splitView = GetSplitView();

            if (splitView != null)
            {
                //TODO: MZ: Probably should be unsubscribed
                splitView.RegisterPropertyChangedCallback(
                    SplitView.IsPaneOpenProperty,
                    OnSplitViewPropertyChanged);
                splitView.RegisterPropertyChangedCallback(
                    SplitView.DisplayModeProperty,
                    OnSplitViewPropertyChanged);

                UpdateIsClosedCompact();
            }

            var rootGrid = GetTemplateChild(c_rootGrid) as Grid;

            if (rootGrid != null)
            {
                m_rootGrid = rootGrid;
            }

            UpdateVisualState(false /*useTransitions*/);
            UpdateItemIndentation();

            var visual = ElementCompositionPreview.GetElementVisual(this);

            NavigationView.CreateAndAttachHeaderAnimation(visual);

            _fullyInitialized = true;
        }
Exemple #2
0
        protected override void OnApplyTemplate()
        {
            // TODO: Uno specific: NavigationView may not be set yet, wait for later #4689
            if (GetNavigationView() is null)
            {
                // Postpone template application for later
                return;
            }

            // 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(this);

            var rootGrid = GetTemplateChild(c_rootGrid) as Grid;

            if (rootGrid != null)
            {
                m_rootGrid = rootGrid;

                var flyoutBase = FlyoutBase.GetAttachedFlyout(rootGrid);
                if (flyoutBase != null)
                {
                    flyoutBase.Closing += OnFlyoutClosing;
                    m_flyoutClosingRevoker.Disposable = Disposable.Create(() => flyoutBase.Closing -= OnFlyoutClosing);
                }
            }

            HookInputEvents();

            IsEnabledChanged += OnIsEnabledChanged;
            m_isEnabledChangedRevoker.Disposable = Disposable.Create(() => IsEnabledChanged -= OnIsEnabledChanged);

            m_toolTip = (ToolTip)GetTemplateChild("ToolTip");

            var splitView = GetSplitView();

            if (splitView != null)
            {
                PrepNavigationViewItem(splitView);
            }
            else
            {
                // If the NVI is not prepared in an ItemPresenter, it will not have reference to SplitView. So check OnLoaded
                // if it the reference has been manually set in NavigationViewItemBase::OnLoaded().
                Loaded -= OnLoaded;
                Loaded += OnLoaded;
            }

            // Retrieve reference to NavigationView
            var nvImpl = GetNavigationView();

            if (nvImpl != null)
            {
                var repeater = GetTemplateChild(c_repeater) as ItemsRepeater;
                if (repeater != null)
                {
                    m_repeater = repeater;

                    // Primary element setup happens in NavigationView
                    repeater.ElementPrepared += nvImpl.OnRepeaterElementPrepared;
                    m_repeaterElementPreparedRevoker.Disposable = Disposable.Create(() => repeater.ElementPrepared -= nvImpl.OnRepeaterElementPrepared);
                    repeater.ElementClearing += nvImpl.OnRepeaterElementClearing;
                    m_repeaterElementClearingRevoker.Disposable = Disposable.Create(() => repeater.ElementClearing -= nvImpl.OnRepeaterElementClearing);

                    repeater.ItemTemplate = nvImpl.GetNavigationViewItemsFactory();
                }

                UpdateRepeaterItemsSource();
            }

            m_flyoutContentGrid = (Grid)GetTemplateChild(c_flyoutContentGrid);

            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);

            _fullyInitialized = true;
        }