Managed applications can provide their own components for the Ribbon by implementing the IRibbonComponentProvider interface and registering it with the RibbonComponentManager. This interface allows application provided to properly work with standard ribbon features such as ribbon search, popup groups, and Hidden Tool resources. The following shows an example of registering a provider:
A RibbonComponent has three basic requirements. It must supply/register a definition of itself. It must create a viewmodel that will serve as a data context for actual WPF control. It must create the WPF control that will be inserted into the ribbon.
The definition must supply a name and that name must be unique for the component type. For example two button definitions should not have the same name. A list of the primary component types are shown below.
Component Type | Definition Type | ViewModel Type | Control Type |
---|---|---|---|
Tab | RibbonTabDefinition | RibbonTabViewModel | RadRibbonTab |
Group | RibbonGroupDefinition | RibbonGroupViewModel | RadRibbonGroup |
Panel | RibbonGroupPanelDefinition | RibbonGroupPanelViewModel | StackPanel,RadCollapsiblePanel, or RadOrderedWrapPanel |
ButtonGroup | RibbonButtonGroupDefinition | RibbonButtonGroupViewModel | RadButtonGroup |
Button | RibbonButtonDefinition | RibbonButtonViewModel | RadRibbonButton |
DropDownButton | RibbonDropDownButtonDefinition | RibbonDropDownButtonViewModel | RadRibbonDropDownButton |
SplitButton | RibbonSplitButtonDefinition | RibbonSplitButtonViewModel | RadRibbonSplitButton |
ToggleButton | RibbonToggleButtonDefinition | RibbonToggleButtonViewModel | RadRibbonToggleButton |
RadioButton | RibbonRadioButtonDefinition | RibbonRadioButtonViewModel | RadRibbonRadioButton |
ComboBox | RibbonComboBoxDefinition | RibbonComboBoxViewModel | RadRibbonComboBox |
Gallery | RibbonGalleryDefinition | RibbonGalleryViewModel | RadRibbonGallery |
The names of the definitions are used to configure the presentation of the Ribbon. To see example configurations look at the XML files in MstnPlatform .
The Bentley.MstnPlatformNET.Ribbon.IRibbonComponentProvider interface definition is shown below:
The class Bentley.MstnPlatformNET.Ribbon.BaseRibbonComponentProvider is provided to allow users to easily implement RibbonComponentProviders which only provide a subset of possible component types. For an example implementation of an IRibbonComponentProvider, see the file MstnPlatform .cs which provides Tab, DropDownButton, and ComboBox components current seen in the Ribbon.
The variable MS_RIBBONCOMPONENTPROVIDERS is used to specify ribbon component providers. The RibbonView application will load the specified provider dll and create the class that is specified by the InstanceOnLoad attribute.
Step 1. Ensure your addin is subclassed from WpfAddin and make sure to define a ThemStyle attribute that specifies where the style resources are located.
Step 2. Define your styles in Common.xaml, below is an example.
If you want the Ribbon to see your components when it collects up a list of items to display the Show/Hide right click menu, the ViewModel set as the DataContext of your component must implement the ISupportsHidingViaUserPrefs interface and provide a non-null UniqueOccurrenceName, UniqueOccurrenceLabel, ParentOccurence, and ItemType. This Interface includes the interface ISupportUniqueOccurrence which is used to add entries into the Ribbon Search box. So if you implement ISupportsHidingViaUserPrefs your component is compatible with both features. These interfaces are also implemented in IRibbonItemViewModel. Since the RibbonComponentManager uses IRibbonItemViewModel, your viewmodels should automatically work with both features. Note, that currently only components that implement ISupportsMstnRelayCommand will be shown in Ribbon Search.
If your component provider is providing a RadRibbonGroup, the ViewModel that serves as the DataContext for the group must implement ISupportsRibbonItems. Each object in the "Items" collection, must have their DataContext set to an IRibbonItemViewModel or at a minimum implement ISupportsHidingViaUserPrefs.
State data is data that you want to save between MicroStation design sessions. To store the state data of ribbon components into the common ribbon state file typically named "MstnRibbonState.xml" if not overridden by variable MS_RIBBONPREFS the following procedure can be followed:
If a property value is changed call RibbonState.RibbonStateData.Dirty = true; to force the state file to be rewritten when the MicroStation session is closed.
The following code is an example implementate of a ViewGroupHistoryState class for the ViewGroupHistory Ribbon Component provider. This can serve as a template for other RibbonComponentProviders.
Below is an example state xml file that contains data from two RibbonCoponent Providers.