Exemplo n.º 1
0
        internal void ShowHideChildren()
        {
            var repeater = m_repeater;

            if (repeater != null)
            {
                bool shouldShowChildren = IsExpanded;
                var  visibility         = shouldShowChildren ? Visibility.Visible : Visibility.Collapsed;
                repeater.Visibility = visibility;

                if (ShouldRepeaterShowInFlyout())
                {
                    if (shouldShowChildren)
                    {
                        // Verify that repeater is parented correctly
                        if (!m_isRepeaterParentedToFlyout)
                        {
                            ReparentRepeater();
                        }

                        // There seems to be a race condition happening which sometimes
                        // prevents the opening of the flyout. Queue callback as a workaround.

                        // TODO: Uno specific - Queue callback for composition rendering is not implemented yet - #4690
                        //SharedHelpers.QueueCallbackForCompositionRendering(() =>
                        //{
                        FlyoutBase.ShowAttachedFlyout(m_rootGrid);
                        //});
                    }
                    else
                    {
                        var flyout = FlyoutBase.GetAttachedFlyout(m_rootGrid);
                        if (flyout != null)
                        {
                            flyout.Hide();
                        }
                    }
                }
            }
        }
Exemplo n.º 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;
        }