private static void AddItems(CommandBarEntryCollection entries, object[] items) { foreach (object item in items) { if (item is string || item is CommandId) { string commandIdentifier = item.ToString(); if (commandIdentifier == "-") { entries.Add(new CommandBarSeparatorEntry()); } else if (commandIdentifier == " ") { entries.Add(new CommandBarSpacerEntry()); } else { CommandBarButtonEntry cbbe = new CommandBarButtonEntry(); cbbe.CommandIdentifier = commandIdentifier; entries.Add(cbbe); } } else if (item is CommandBarEntry) { entries.Add((CommandBarEntry)item); } else { Trace.Fail("Unexpected command bar definition item"); throw new ArgumentException("Unexpected command bar definition item"); } } }
/// <summary> /// Sets the specified array as the items of the collection. /// </summary> /// <param name="editValue">The collection to edit.</param> /// <param name="value">An array of objects to set as the collection items.</param> /// <returns>The newly created collection object or, otherwise, the collection indicated by the editValue parameter.</returns> protected override object SetItems(object editValue, object[] value) { CommandBarEntryCollection commandBarEntryCollection = (CommandBarEntryCollection)editValue; commandBarEntryCollection.Clear(); foreach (CommandBarEntry commandBarEntry in value) { commandBarEntryCollection.Add(commandBarEntry); } return(commandBarEntryCollection); }