示例#1
0
        /// <summary>
        /// Ustawia stan początkowy ribbon bara.
        /// </summary>
        private void ResetRibbonBar()
        {
            // usunięcie tabów z contextual tabów
            for (int i = 0; i < mainRibbonBar.ContextualTabGroups.Count; i++)
            {
                if (mainRibbonBar.ContextualTabGroups[i] is ContextualTabGroup)
                {
                    ContextualTabGroup ctg = mainRibbonBar.ContextualTabGroups[i] as ContextualTabGroup;

                    if (ctg != managementContextualTabGroup)
                    {
                        for (int ii = 0; ii < ctg.TabItems.Count; ii++)
                        {
                            ctg.TabItems.RemoveAt(ii);
                            ii--;
                        }
                    }
                }
            }

            // usunięcie contextual tabów
            for (int i = 0; i < mainRibbonBar.ContextualTabGroups.Count; i++)
            {
                if (this.mainRibbonBar.ContextualTabGroups[i] != managementContextualTabGroup)
                {
                    this.mainRibbonBar.ContextualTabGroups.RemoveAt(i);
                    i--;
                }
            }

            // usunięcie tabów
            for (int i = 0; i < mainRibbonBar.CommandTabs.Count; i++)
            {
                if (this.mainRibbonBar.CommandTabs[i] != mainWindowsRibbonTab && this.mainRibbonBar.CommandTabs[i] != managementContextualTabGroup.TabItems[0])
                {
                    this.mainRibbonBar.CommandTabs.RemoveAt(i);
                    i--;
                }
            }

            mainWindowsRibbonTab.IsSelected = true;
        }
        private void OnLayoutUpdated(object sender, EventArgs e)
        {
            if (Ribbon == null || ContextualTabGroup == null)
            {
                return;
            }

            if (!ContextualTabGroup.IsVisible)
            {
                IsFirstInContextualGroup = false;
                IsLastInContextualGroup  = false;
                return;
            }

            var contextualTabRelativeLeft  = ContextualTabGroup.TranslatePoint(new Point(), Ribbon).X;
            var contextualTabRelativeRight = contextualTabRelativeLeft + ContextualTabGroup.ActualWidth;

            var thisLeft  = TranslatePoint(new Point(), Ribbon).X;
            var thisRight = thisLeft + ActualWidth;

            IsFirstInContextualGroup = Math.Abs(contextualTabRelativeLeft - thisLeft) < 2;
            IsLastInContextualGroup  = Math.Abs(contextualTabRelativeRight - thisRight) < 2;
        }
        /// <summary>
        /// Initializes a new <see cref="ContextualTabGroupUIAdapter"/>
        /// </summary>
        /// <param name="tabGroup">ContextualTabGroup represented by the ui adapter</param>
        public ContextualTabGroupUIAdapter(ContextualTabGroup tabGroup)
        {
            Guard.ArgumentNotNull(tabGroup, "tabGroup");

            this.tabGroup = tabGroup;
        }
        private void radBtnRemoveTabs_Click(object sender, EventArgs e)
        {
            int indexOfSelectedItem = this.radListBoxTabItems.SelectedIndex;

            RadListBoxItem[] itemsToRemove = new RadListBoxItem[this.radListBoxTabItems.SelectedItems.Count];

            for (int index = 0; index < this.radListBoxTabItems.SelectedItems.Count; index++)
            {
                itemsToRemove[index] = this.radListBoxTabItems.SelectedItems[index] as RadListBoxItem;
            }

            for (int i = 0; i < itemsToRemove.Length; i++)
            {
                RadListBoxItem currentItem = itemsToRemove[i] as RadListBoxItem;

                RibbonTab tabToRemove = currentItem.Tag as RibbonTab;

                IComponentChangeService componentChangeService = this.host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

                if (componentChangeService != null)
                {
                    componentChangeService.OnComponentChanging(this.host.RootComponent, TypeDescriptor.GetProperties(this.host.RootComponent)["CommandTabs"]);

                    this.collection.Remove(tabToRemove);

                    if (tabToRemove.ContextualTabGroup != null)
                    {
                        ContextualTabGroup tabGroup = tabToRemove.ContextualTabGroup;
                        tabGroup.TabItems.Remove(tabToRemove);
                    }

                    componentChangeService.OnComponentChanged(this.host.RootComponent, TypeDescriptor.GetProperties(this.host.RootComponent)["CommandTabs"], null, null);

                    if (newlyAddedItems.Contains(tabToRemove))
                    {
                        this.newlyAddedItems.Remove(tabToRemove);
                    }

                    this.radListBoxTabItems.Items.Remove(currentItem);
                    this.host.DestroyComponent(tabToRemove);
                }
            }


            if (indexOfSelectedItem >= 0 && indexOfSelectedItem <= this.radListBoxTabItems.Items.Count)
            {
                if (indexOfSelectedItem == this.radListBoxTabItems.Items.Count)
                {
                    this.radListBoxTabItems.SelectedIndex = indexOfSelectedItem - 1;
                }
                else
                {
                    this.radListBoxTabItems.SelectedIndex = indexOfSelectedItem;
                }
            }

            if (this.radListBoxTabItems.Items.Count == 0)
            {
                this.propGridTabProperties.SelectedObject = null;
            }
        }