Ribbon and Command Bars Example for WPF

Nevron NOV Chart for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF Chart examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Ribbon and Command Bars Example for WPF Description

This example demonstrates how to add a commanding interface to the NOV Chart and how to switch between ribbon and command bars.


Ribbon and Command Bars Example

C# Ribbon and Command Bars Example Code for Nevron Chart for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NRibbonAndCommandBarsExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

		#region Example

		public NWidget CreateExampleContent()
		{
			// Create a simple chart
			m_ChartView = new NChartView();

			m_ChartView.Document.HistoryService.Pause();
			try
			{
				InitChart(m_ChartView.Document);
			}
			finally
			{
				m_ChartView.Document.HistoryService.Resume();
			}

			// Create and execute a ribbon UI builder
			m_RibbonBuilder = new NChartRibbonBuilder();
			return m_RibbonBuilder.CreateUI(m_ChartView);
		}
		public NWidget CreateExampleControls()
		{
			// Switch UI button
			NButton switchUIButton = new NButton(SwitchToCommandBars);
			switchUIButton.VerticalPlacement = ENVerticalPlacement.Top;
			switchUIButton.Click += OnSwitchUIButtonClick;

			return switchUIButton;
		}
		public string GetExampleDescription()
		{
			return "

This example demonstrates how to add a commanding interface to the NOV Chart and how to switch between ribbon and command bars.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Chart Ribbon Overview", "https://www.nevron.com/docs/openvision/chart-ribbon-overview.html"), ("Chart Command Bars Overview", "https://www.nevron.com/docs/openvision/chart-command-bars-overview.html"), }; } private void InitChart(NChartDocument chartDocument) { NChartViewSurface chartSurface = chartDocument.Content; chartSurface.CreatePredefinedChart(ENPredefinedChartType.Cartesian); // Set the title chartSurface.Titles[0].Text = "Chart Commanding Interface"; // Configure the chart NCartesianChart chart = (NCartesianChart)chartSurface.Charts[0]; chart.Enable3D = true; chart.Projection.SetPredefinedProjection(ENPredefinedProjection.Perspective); // Add an interlace stripe NLinearScale linearScale = chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLinearScale; NScaleStrip strip = new NScaleStrip(new NColorFill(ENNamedColor.Beige), null, true, 0, 0, 1, 1); strip.Interlaced = true; linearScale.Strips.Add(strip); // Add a bar series Random random = new Random(); for (int i = 0; i < 6; i++) { NBarSeries bar = new NBarSeries(); bar.Name = "Bar" + i.ToString(); bar.MultiBarMode = ENMultiBarMode.Clustered; bar.DataLabelStyle = new NDataLabelStyle(false); bar.ValueFormatter = new NNumericValueFormatter("0.###"); chart.Series.Add(bar); for (int j = 0; j < 6; j++) { bar.DataPoints.Add(new NBarDataPoint(random.Next(10, 100))); } } } #endregion #region Implementation private void SetUI(NCommandUIHolder oldUiHolder, NWidget widget) { if (oldUiHolder.ParentNode is NTabPage) { ((NTabPage)oldUiHolder.ParentNode).Content = widget; } else if (oldUiHolder.ParentNode is NPairBox) { ((NPairBox)oldUiHolder.ParentNode).Box1 = widget; } } #endregion #region Event Handlers private void OnSwitchUIButtonClick(NEventArgs arg) { NButton switchUIButton = (NButton)arg.TargetNode; NLabel label = (NLabel)switchUIButton.Content; // Remove the chart view from its parent NCommandUIHolder uiHolder = m_ChartView.GetFirstAncestor(); m_ChartView.ParentNode.RemoveChild(m_ChartView); if (label.Text == SwitchToRibbon) { // We are in "Command Bars" mode, so switch to "Ribbon" label.Text = SwitchToCommandBars; // Create the ribbon SetUI(uiHolder, m_RibbonBuilder.CreateUI(m_ChartView)); } else { // We are in "Ribbon" mode, so switch to "Command Bars" label.Text = SwitchToRibbon; // Create the command bars if (m_CommandBarBuilder == null) { m_CommandBarBuilder = new NChartCommandBarBuilder(); } SetUI(uiHolder, m_CommandBarBuilder.CreateUI(m_ChartView)); } } #endregion #region Fields private NChartView m_ChartView; private NChartRibbonBuilder m_RibbonBuilder; private NChartCommandBarBuilder m_CommandBarBuilder; #endregion #region Static Methods #endregion #region Constants private const string SwitchToCommandBars = "Switch to Command Bars"; private const string SwitchToRibbon = "Switch to Ribbon"; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Ribbon and Command Bars Example for WPF Solution

VB.NET Ribbon and Command Bars Example Code for Nevron Chart for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System

Class MainWindow

#Region "Constructors"

	Public Sub New()
		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NRibbonAndCommandBarsExample"

		' Create the NOV example and its controls
		Dim exampleContent As NWidget = CreateExampleContent()
		Dim exampleControls As NWidget = CreateExampleControls()
		If Not exampleControls Is Nothing Then
			exampleControls.PreferredWidth = 300
		End If

		' Place the example and its controls in a pair box
		Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
		pairBox.FillMode = ENStackFillMode.First
		pairBox.FitMode = ENStackFitMode.First
		pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)

		' Host the example in the form
		Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
		Content = host
	End Sub


#End Region

#Region "Example"

        Public Function CreateExampleContent() As NWidget
            ' Create a simple chart
            m_ChartView = New NChartView()

            m_ChartView.Document.HistoryService.Pause()
            Try
                InitChart(m_ChartView.Document)
            Finally
                m_ChartView.Document.HistoryService.Resume()
            End Try

            ' Create and execute a ribbon UI builder
            m_RibbonBuilder = New NChartRibbonBuilder()
            Return m_RibbonBuilder.CreateUI(m_ChartView)
        End Function
        Public Function CreateExampleControls() As NWidget
            ' Switch UI button
            Dim switchUIButton As NButton = New NButton(SwitchToCommandBars)
            switchUIButton.VerticalPlacement = ENVerticalPlacement.Top
            switchUIButton.Click += AddressOf OnSwitchUIButtonClick

            Return switchUIButton
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to add a commanding interface to the NOV Chart and how to switch between ribbon and command bars.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Chart Ribbon Overview", "https://www.nevron.com/docs/openvision/chart-ribbon-overview.html"), ("Chart Command Bars Overview", "https://www.nevron.com/docs/openvision/chart-command-bars-overview.html")} End Function Private Sub InitChart(chartDocument As NChartDocument) Dim chartSurface = chartDocument.Content chartSurface.CreatePredefinedChart(ENPredefinedChartType.Cartesian) ' Set the title chartSurface.Titles(0).Text = "Chart Commanding Interface" ' Configure the chart Dim chart = CType(chartSurface.Charts(0), NCartesianChart) chart.Enable3D = True chart.Projection.SetPredefinedProjection(ENPredefinedProjection.Perspective) ' Add an interlace stripe Dim linearScale As NLinearScale = TryCast(chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale) Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(ENNamedColor.Beige), Nothing, True, 0, 0, 1, 1) strip.Interlaced = True linearScale.Strips.Add(strip) ' Add a bar series Dim random As Random = New Random() For i = 0 To 5 Dim bar As NBarSeries = New NBarSeries() bar.Name = "Bar" & i.ToString() bar.MultiBarMode = ENMultiBarMode.Clustered bar.DataLabelStyle = New NDataLabelStyle(False) bar.ValueFormatter = New NNumericValueFormatter("0.###") chart.Series.Add(bar) For j = 0 To 5 bar.DataPoints.Add(New NBarDataPoint(random.Next(10, 100))) Next Next End Sub #End Region #Region "Implementation" Private Sub SetUI(oldUiHolder As NCommandUIHolder, widget As NWidget) If TypeOf oldUiHolder.ParentNode Is NTabPage Then CType(oldUiHolder.ParentNode, NTabPage).Content = widget ElseIf TypeOf oldUiHolder.ParentNode Is NPairBox Then CType(oldUiHolder.ParentNode, NPairBox).Box1 = widget End If End Sub #End Region #Region "Event Handlers" Private Sub OnSwitchUIButtonClick(arg As NEventArgs) Dim switchUIButton = CType(arg.TargetNode, NButton) Dim label = CType(switchUIButton.Content, NLabel) ' Remove the chart view from its parent Dim uiHolder As NCommandUIHolder = m_ChartView.GetFirstAncestor(Of NCommandUIHolder)() m_ChartView.ParentNode.RemoveChild(m_ChartView) If Equals(label.Text, SwitchToRibbon) Then ' We are in "Command Bars" mode, so switch to "Ribbon" label.Text = SwitchToCommandBars ' Create the ribbon SetUI(uiHolder, m_RibbonBuilder.CreateUI(m_ChartView)) Else ' We are in "Ribbon" mode, so switch to "Command Bars" label.Text = SwitchToRibbon ' Create the command bars If m_CommandBarBuilder Is Nothing Then m_CommandBarBuilder = New NChartCommandBarBuilder() End If SetUI(uiHolder, m_CommandBarBuilder.CreateUI(m_ChartView)) End If End Sub #End Region #Region "Fields" Private m_ChartView As NChartView Private m_RibbonBuilder As NChartRibbonBuilder Private m_CommandBarBuilder As NChartCommandBarBuilder #End Region #Region "Static Methods" #End Region #Region "Constants" Private Const SwitchToCommandBars As String = "Switch to Command Bars" Private Const SwitchToRibbon As String = "Switch to Ribbon" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Ribbon and Command Bars Example for WPF Solution