예제 #1
0
        public Panel CreateSplitButton(string name, string text, Action <StackedItem> itemsAction)
        {
            var buttonControl = new SplitButtonControl(this, name, text);

            var splitButton = buttonControl.Finish();

            var stackedItem = new StackedItem(nameConvention);

            itemsAction.Invoke(stackedItem);

            var pushButtons = stackedItem
                              .Buttons
                              .Select(x => x.Finish())
                              .Cast <PushButtonData>()
                              .Select(x => splitButton.AddPushButton(x))
                              .ToList();

            splitButton.CurrentButton = pushButtons[stackedItem.GetDefaultButtonIndex()];

            return(this);
        }
예제 #2
0
        /// <summary>
        /// Create new Stacked items at the panel
        /// </summary>
        /// <param name="action">Action where you must add items to the stacked panel</param>
        /// <returns>Panel where stacked items was created</returns>
        public Panel CreateStackedItems(Action <StackedItem> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var stackedItem = new StackedItem(nameConvention);

            action.Invoke(stackedItem);

            if (stackedItem.ItemsCount < 2 || stackedItem.ItemsCount > 3)
            {
                throw new InvalidOperationException("You must create 2 or three items in the StackedItems");
            }

            RibbonItemData item1 = stackedItem.Buttons[0].Finish();
            RibbonItemData item2 = stackedItem.Buttons[1].Finish();

            IList <RibbonItem> ribbonItems;

            if (stackedItem.ItemsCount == 3)
            {
                RibbonItemData item3 = stackedItem.Buttons[2].Finish();
                ribbonItems = Source.AddStackedItems(item1, item2, item3);
            }
            else
            {
                ribbonItems = Source.AddStackedItems(item1, item2);
            }

            for (var i = 0; i < stackedItem.Buttons.Count; ++i)
            {
                stackedItem.Buttons[i].DoPostProcessing(ribbonItems[i]);
            }

            return(this);
        }