Exemplo n.º 1
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or
        /// internal processes call System.Windows.FrameworkElement.ApplyTemplate().
        /// </summary>
        public override void OnApplyTemplate()
        {
            if (this.showAbove != null)
            {
                this.showAbove.Click -= this.OnShowAboveClick;
            }

            if (this.showBelow != null)
            {
                this.showBelow.Click -= this.OnShowBelowClick;
            }

            this.showAbove = this.GetTemplateChild("PART_ShowAbove") as MenuItem;
            this.showBelow = this.GetTemplateChild("PART_ShowBelow") as MenuItem;

            if (this.showAbove != null)
            {
                this.showAbove.Click += this.OnShowAboveClick;
            }

            if (this.showBelow != null)
            {
                this.showBelow.Click += this.OnShowBelowClick;
            }

            if (this.menuDownButton != null)
            {
                foreach (var item in this.QuickAccessItems)
                {
                    this.menuDownButton.Items.Remove(item);
                    item.InvalidateProperty(QuickAccessMenuItem.TargetProperty);
                }
            }
            else if (this.quickAccessItems != null)
            {
                foreach (var item in this.quickAccessItems)
                {
                    this.RemoveLogicalChild(item);
                }
            }

            this.menuDownButton = this.GetTemplateChild("PART_MenuDownButton") as DropDownButton;

            if (this.menuDownButton != null &&
                this.quickAccessItems != null)
            {
                for (var i = 0; i < this.quickAccessItems.Count; i++)
                {
                    this.menuDownButton.Items.Insert(i + 1, this.quickAccessItems[i]);
                    this.quickAccessItems[i].InvalidateProperty(QuickAccessMenuItem.TargetProperty);
                }
            }

            if (this.toolBarDownButton != null)
            {
                this.toolBarDownButton.DropDownOpened -= this.OnToolBarDownOpened;
                this.toolBarDownButton.DropDownClosed -= this.OnToolBarDownClosed;
            }

            this.toolBarDownButton = this.GetTemplateChild("PART_ToolbarDownButton") as DropDownButton;

            if (this.toolBarDownButton != null)
            {
                this.toolBarDownButton.DropDownOpened += this.OnToolBarDownOpened;
                this.toolBarDownButton.DropDownClosed += this.OnToolBarDownClosed;
            }

            // ToolBar panels
            this.toolBarPanel         = this.GetTemplateChild("PART_ToolBarPanel") as Panel;
            this.toolBarOverflowPanel = this.GetTemplateChild("PART_ToolBarOverflowPanel") as Panel;

            if (this.rootPanel != null)
            {
                this.RemoveLogicalChild(this.rootPanel);
            }

            this.rootPanel = this.GetTemplateChild("PART_RootPanel") as Panel;

            if (this.rootPanel != null)
            {
                this.AddLogicalChild(this.rootPanel);
            }

            // Clears cache
            this.cachedDeltaWidth            = 0;
            this.cachedNonOverflowItemsCount = this.GetNonOverflowItemsCount(this.ActualWidth);
            this.cachedConstraint            = new Size();
        }