Nevron Open Vision Documentation
Ribbon
Diagram Ribbon Builder

NOV Diagram provides a ribbon builder that can be used to create and associate ribbon commanding UI to a drawing view. The builder is represented by the NDiagramRibbonBuilder class.

The easiest way to create a drawing view with ribbon is to use the NDrawingViewWithRibbon class. The example below demonstrates how to create a drawing view with ribbon hosted in a NOV widget host. You can then add this host to a form's Controls collection if you are creating a WinForms application, set it as the Content of a WPF window in a WPF application project or to the ContentView of a Xamarin.Mac window.

Create a drawing view with ribbon
Copy Code
NDrawingViewWithRibbon ribbonUI = new NDrawingViewWithRibbon(); // Create a drawing view with a ribbon
NDrawingView drawingView = ribbonUI.View; // Get the drawing view

// Create a NOV widget host that hosts the drawing view with ribbon
NNovWidgetHost<NWidget> novHost = new NNovWidgetHost<NWidget>(ribbonUI);

Another way to create a ribbon based commanding UI and associate it with a drawing view is:

Create ribbon UI using a ribbon builder
Copy Code
NDiagramRibbonBuilder ribbonBuilder = new NDiagramRibbonBuilder();
NWidget uiWidget = ribbonBuilder.CreateUI(drawingView);

To rename a ribbon tab or a ribbon group command builder, change it's name property prior to using it for building the ribbon UI. The following piece of code demonstrates how to rename the "Home" tab page and the "Font" ribbon group:

Rename ribbon tab and group
Copy Code
// Rename the "Home" ribbon tab page
NRibbonTabPageBuilder homeTabBuilder = m_RibbonBuilder.TabPageBuilders[NDiagramRibbonBuilder.TabPageHomeName];
homeTabBuilder.Name = "Start";

// Rename the "Font" ribbon group of the "Home" tab page
NRibbonGroupBuilder fontGroupBuilder = homeTabBuilder.RibbonGroupBuilders[NHomeTabPageBuilder.GroupFontName];
fontGroupBuilder.Name = "Text";
Removing Commands

To remove all widgets associated with specific commands from the commanding UI, use the RemoveCommands method of the drawing view with ribbon:

Remove commands
Copy Code
// Create an array of commands to remove
NCommand[] commandsToRemove = new NCommand[] {
    NDrawingView.OpenCommand,
    NDrawingView.SaveAsCommand,
    NDrawingView.SaveCommand
};

NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
drawingViewWithRibbon.RemoveCommands(commandsToRemove);

If you are using the Visual Studio designer, you can click the Customize Ribbon smart tag of your NDrawingViewWithRibbonControl and uncheck the commands you want to hide from the ribbon:

Modifying Ribbon Group Builders Collection

If you want to remove a given ribbon tab page, you can easily do so by using the Remove method of the TabPageBuilders collection of the diagram ribbon builder. To remove a ribbon group from a tab page, you should use the Remove method of the RibbonGroupBuilders collection of the ribbon group builder.

The names of all diagram ribbon tab pages are exposed as constants in the NDiagramRibbonBuilder class. Each of the tab page builders exposes as constants the names of its ribbon group builders. The following piece of code demonstrates how to remove the "Editing" ribbon group of the "Home" tab page of the diagram ribbon:

Remove ribbon group
Copy Code
NRibbonTabPageBuilder homeTabBuilder = ribbonBuilder.TabPageBuilders[NDrawingRibbonBuilder.TabPageHomeName];
homeTabBuilder.RibbonGroupBuilders.Remove(NHomeTabPageBuilder.GroupEditingName);

In order to add or insert your own ribbon group builders, you can use the Add or Insert methods of the RibbonGroupBuilders collection respectively.

Add custom ribbon group
Copy Code
NRibbonTabPageBuilder homeTabBuilder = ribbonBuilder.TabPageBuilders[NDrawingRibbonBuilder.TabPageHomeName];
homeTabBuilder.RibbonGroupBuilders.Insert(0, new CustomRibbonGroupBuilder());
Custom Ribbon Group Builders

To create a custom ribbon group builder you should create a class, which inherits NRibbonGroupBuilder:

Custom ribbon group builder
Copy Code
public class CustomRibbonGroupBuilder : NRibbonGroupBuilder
{
    public CustomRibbonGroupBuilder()
        : base("Custom Group", NResources.Image_Ribbon_16x16_smiley_png)
    {
    }

    protected override void AddRibbonGroupItems(NRibbonGroupItemCollection items)
    {
        // Add the "Copy" command
        items.Add(CreateRibbonButton(NResources.Image_Ribbon_32x32_clipboard_copy_png,
            Nevron.Nov.Presentation.NResources.Image_Edit_Copy_png, NDrawingView.CopyCommand));

        // Add the custom command
        items.Add(CreateRibbonButton(NResources.Image_Ribbon_32x32_smiley_png,
            NResources.Image_Ribbon_16x16_smiley_png, CustomCommand));
    }
}
See Also

UI

Send Feedback