/// <summary> /// Adds the ribbon item to the specified <see cref="ItemsControl"/>. /// </summary> /// <param name="itemsControl">The items control.</param> /// <param name="ribbonItem">The ribbon item.</param> public static void AddRibbonItem(this ItemsControl itemsControl, IRibbonItem ribbonItem) { var ribbonControl = ribbonItem as IRibbonControl; if (ribbonControl != null) { Control ribbonItemControl = null; var ribbonButton = ribbonControl as IRibbonButton; if (ribbonButton != null) { var ribbonSplitButton = ribbonButton as IRibbonSplitButton; if (ribbonSplitButton != null) { if (ribbonButton.Command != null) { ribbonItemControl = itemsControl.AddSplitButton(ribbonSplitButton.Items, ribbonButton.ItemHeader, ribbonButton.ItemImage, ribbonButton.ItemImage, ribbonButton.Command); } else { ribbonItemControl = itemsControl.AddSplitButton(ribbonSplitButton.Items, ribbonButton.ItemHeader, ribbonButton.ItemImage, ribbonButton.ItemImage, ribbonButton.CommandName); } } else { if (ribbonButton.Command != null) { ribbonItemControl = itemsControl.AddButton(ribbonButton.ItemHeader, ribbonButton.ItemImage, ribbonButton.ItemImage, ribbonButton.Command); } else { ribbonItemControl = itemsControl.AddButton(ribbonButton.ItemHeader, ribbonButton.ItemImage, ribbonButton.ItemImage, ribbonButton.CommandName); } } } var ribbonComboBox = ribbonControl as IRibbonComboBox; if (ribbonComboBox != null) { ribbonItemControl = itemsControl.AddComboBox(ribbonComboBox.ItemHeader, ribbonComboBox.ItemsSource, ribbonComboBox.SelectedItem); } var ribbonContentControl = ribbonControl as IRibbonContentControl; if (ribbonContentControl != null) { ribbonItemControl = itemsControl.AddContentControl(ribbonControl.ItemHeader, ribbonContentControl.ContentTemplate); } if (ribbonItemControl != null) { if (ribbonControl.Layout != null && itemsControl is RibbonGroupBox) { ((RibbonGroupBox)itemsControl).ApplyLayout(ribbonItemControl, ribbonControl.Layout); } if (ribbonControl.Style != null) { ribbonItemControl.Style = ribbonControl.Style; } if (ribbonControl.ToolTip != null) { ribbonItemControl.ToolTip = new ScreenTip { Title = ribbonControl.ToolTip.Title, Text = ribbonControl.ToolTip.Text, Width = ribbonControl.ToolTip.Width, }; } } } var ribbonItemsCollection = ribbonItem as IRibbonItemsCollection; if (ribbonItemsCollection != null) { var ribbonGallery = ribbonItemsCollection as IRibbonGallery; if (ribbonGallery != null) { itemsControl.AddGallery(ribbonGallery.Items, ribbonGallery.Orientation, ribbonGallery.Selectable, ribbonGallery.ItemWidth, ribbonGallery.ItemHeight, ribbonGallery.MinItemsInRow, ribbonGallery.MaxItemsInRow, ribbonGallery.ItemContainerStyle); } } }