NOV Chart provides two ways to create a chart view with a ribbon commanding UI.
The easiest way to create a ribbon commanding UI for a chart view is to use the NChartViewWithRibbon widget or if you are not creating a cross-platform application - to drop an NChartViewWithRibbonControl to a form/window using the Visual Studio Designer. You can then use the following approaches to modify the ribbon:
1. Hiding Ribbon Tab Pages and Ribbon Groups
To hide an element from the ribbon use the corresponding Get... method of the NChartViewWithRibbon or the NChartViewWithRibbonControl class and set its Visibility property to Collapsed:
- GetApplicationMenu - gets the ribbon application menu.
- GetRibbonTabPage - gets the ribbon tab page with a given title.
- GetRibbonGroup - gets the ribbon group with a given groupTitle in the tab page with a specified pageTitle.
- GetRibbonSearchBox - gets the ribbon search box.
- GetRibbonQuickAccessToolbar - gets the ribbon quick access toolbar.
- GetStatusBar - gets the status bar. Returns null for a chart view with ribbon.
The following code snippet hides the "View" ribbon tab page and the "Export" ribbon group of the "Home" ribbon tab page:
Hide ribbon tab pages and ribbon groups |
Copy Code
|
// Hide the "View" ribbon tab page
nChartViewWithRibbonControl1.GetRibbonTabPage(NChartRibbonBuilder.TabPageViewName)
.Header.Visibility = ENVisibility.Collapsed;
// Hide the "Export" ribbon group of the "Home" ribbon tab page
nChartViewWithRibbonControl1.GetRibbonGroup(NChartRibbonBuilder.TabPageHomeName, NHomeTabPageBuilder.GroupExportName)
.Visibility = ENVisibility.Collapsed;
|
Note that instead of using string literals like "View", it is better to use the string constants defined in the NChartRibbonBuilder class to get ribbon tab page names as shown in the code snippet above. You should use the constants in the corresponding tab page builder to get ribbon group names, for example, NHomeTabPageBuilder.GroupExportName.
2. Removing Commands
To hide all widgets associated with specific commands from the commanding UI, use the RemoveCommands method of the chart view with ribbon. For example, the code snippet below removes the Open, Save, and Save As commands and hides the widgets associated with them from the ribbon:
Remove commands |
Copy Code
|
NChartViewWithRibbon chartViewWithRibbon = new NChartViewWithRibbon();
chartViewWithRibbon.RemoveCommands(NChartView.OpenCommand, NChartView.SaveCommand, NChartView.SaveAsCommand);
|
You can also create a NOV Chart ribbon commanding UI using the NOV Chart ribbon builder. This gives you greater flexibility and more ways to customize the NOV Chart ribbon, including an option to add custom commands to the ribbon:
Creating a NOV Chart ribbon UI |
Copy Code
|
NChartRibbonBuilder ribbonBuilder = new NChartRibbonBuilder();
NCommandUIHolder chartViewWithRibbon = ribbonBuilder.CreateUI(chartView);
|
1. Renaming Ribbon Tabs and Groups
To rename a ribbon tab or a ribbon group command builder, change its name property before 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 the ribbon tab and group |
Copy Code
|
// Rename the "Home" ribbon tab page
NRibbonTabPageBuilder homeTabBuilder = ribbonBuilder.TabPageBuilders[NChartRibbonBuilder.TabPageHomeName];
homeTabBuilder.Name = "Start";
// Rename the "Export" ribbon group of the "Home" tab page
NRibbonGroupBuilder exportGroupBuilder = homeTabBuilder.RibbonGroupBuilders[NHomeTabPageBuilder.GroupExportName];
exportGroupBuilder.Name = "Custom Name";
|
2. Modifying the 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 chart 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 chart ribbon tab pages are exposed as constants in the NChartRibbonBuilder 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 "Export" ribbon group of the "Home" tab page of the chart ribbon:
Remove ribbon group |
Copy Code
|
NRibbonTabPageBuilder homeTabBuilder = ribbonBuilder.TabPageBuilders[NChartRibbonBuilder.TabPageHomeName];
homeTabBuilder.RibbonGroupBuilders.Remove(NHomeTabPageBuilder.GroupExportName);
|
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[NChartRibbonBuilder.TabPageHomeName];
homeTabBuilder.RibbonGroupBuilders.Insert(0, new CustomRibbonGroupBuilder());
|
3. Removing Commands
To hide all widgets associated with specific commands from the commanding UI, use the RemoveCommands method of the command UI holder created by the ribbon builder. For example, the code snippet below removes the Open, Save, and Save As commands and hides the widgets associated with them from the ribbon:
Remove commands |
Copy Code
|
NChartRibbonBuilder ribbonBuilder = new NChartRibbonBuilder();
NCommandUIHolder chartViewWithRibbon = ribbonBuilder.CreateUI(chartView);
chartViewWithRibbon.RemoveCommands(NChartView.OpenCommand, NChartView.SaveCommand, NChartView.SaveAsCommand);
|
4. Custom Ribbon Group Builders
To create a custom ribbon group builder you should create a class, that 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 "Open" command
items.Add(CreateRibbonButton(Nevron.Nov.Presentation.NResources.Image_Ribbon_AppMenu_Open_png,
Nevron.Nov.Presentation.NResources.Image_File_Open_png, NChartView.OpenCommand));
// Add the custom command
items.Add(CreateRibbonButton(NResources.Image_Ribbon_32x32_smiley_png,
NResources.Image_Ribbon_16x16_smiley_png, CustomCommand));
}
}
|
To see how to define a custom command and a custom command action, take a look at the Chart Commanding Overview topic.