Command Bars Customization Example for Blazor

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

Command Bars Customization Example for Blazor Description

This example demonstrates how to customize the NOV schedule command bars (menus and toolbars).


Command Bars Customization Example

C# Command Bars Customization Example Code for Nevron Schedule for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Schedule;
using Nevron.Nov.Schedule.Commands;
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 - NCommandBarsCustomizationExample";

			// 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 schedule
			m_ScheduleView = new NScheduleView();

			m_ScheduleView.Document.PauseHistoryService();
			try
			{
				InitSchedule(m_ScheduleView.Content);
			}
			finally
			{
				m_ScheduleView.Document.ResumeHistoryService();
			}

			// Add the custom command action to the schedule view's commander
			m_ScheduleView.Commander.Add(new CustomCommandAction());

			// Create and configure command bars UI builder
			// Remove the "Edit" menu and insert a custom one
			NScheduleCommandBarBuilder commandBarBuilder = new NScheduleCommandBarBuilder();
			commandBarBuilder.MenuDropDownBuilders.Remove(NScheduleCommandBarBuilder.MenuEditName);
			commandBarBuilder.MenuDropDownBuilders.Insert(1, new CustomMenuBuilder());

			// Remove the "Standard" toolbar and insert a custom one
			commandBarBuilder.ToolBarBuilders.Remove(NScheduleCommandBarBuilder.ToolbarStandardName);
			commandBarBuilder.ToolBarBuilders.Insert(0, new CustomToolBarBuilder());

			// Create the commanding UI
			NCommandUIHolder scheduleViewWithCommandBars = commandBarBuilder.CreateUI(m_ScheduleView);

			// Remove the Open and Save commands
			scheduleViewWithCommandBars.RemoveCommands(NScheduleView.OpenCommand, NScheduleView.SaveCommand, NScheduleView.SaveAsCommand);

			return scheduleViewWithCommandBars;
		}
		public NWidget CreateExampleControls()
		{
			return null;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to customize the NOV schedule command bars (menus and toolbars).

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Schedule Command Bars via Code", "https://www.nevron.com/docs/openvision/schedule-command-bars-via-code.html"), ("Schedule Commanding Overview", "https://www.nevron.com/docs/openvision/schedule-commanding-overview.html"), }; } #endregion #region Implementation private void InitSchedule(NSchedule schedule) { DateTime start = DateTime.Now; // Create an appointment NAppointment appointment = new NAppointment("Meeting", start, start.AddHours(2)); schedule.Appointments.Add(appointment); schedule.ScrollToTime(start.TimeOfDay); } #endregion #region Event Handlers #endregion #region Fields private NScheduleView m_ScheduleView; #endregion #region Static Methods #endregion #region Constants public static readonly NCommand CustomCommand = NCommand.Create(typeof(Nevron.Nov.Examples.Schedule.NCommandBarsCustomizationExample), "CustomCommand", "Custom Command"); #endregion #region Nested Types public class CustomMenuBuilder : NMenuDropDownBuilder { public CustomMenuBuilder() : base("Custom Menu") { } protected override void AddItems(NMenuItemCollection items) { // Add the "Add Appointment" menu item items.Add(CreateMenuItem(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("PD94bWwgdmVyc2lvbj0iMS4wIiB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ics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABsElEQVR4AYWTQ7BjQRSGZz3cjM04Y9u2bdu2bdu29bx83jxzvI79z+munDiVW/Vd/Lf/g0aF0MvyeUJT4ipRTsDLb+ImoQ4zhJifEYjBp2jmfAJWAsmTYP/mN9m+SE08WfsVar7PZuPHcajfRI2M68NFEGn6+3wM6jZSovTRyMAgH9jcgDM5v0/E5+ODUbOBCgeX9oAnfiLccRNxf1c/qV3Z1Ed+B7SjFQHOsiAyplHmSjUUuLZZDoYMemKw1F4eHAjX96AAt7l3MIifIDOZP/k1D5kubuxDCcazxvwTAZyBoouyImUykDCJmMjISeTyA+EAbMbjvf1xaFlP7FrYHTvmS7B7UQ+cWNULj/f0o5bCA+Tyh8jSTKFGU4UGzZXBNCOtWm2FrCYgwB8R4DQL4ue2ud3QpLkGOp0uiGYUZM6YDkDipMAAN0WAOgQYN5XYv0crNGyqhoJMCpUGjZqp0am9HuaP42H9EtRCC94LN1m0EkiahDeHB2LNjC5YOaUzHu3uL6uzBZtfhe7G7KDV+M4rEHH2i0KPQlAlMXga60TW8U5sHuEkXEQBcYFoGDr+P5RkQoMvtntjAAAAAElFTkSuQmCC")), CustomCommand)); } } public class CustomToolBarBuilder : NToolBarBuilder { public CustomToolBarBuilder() : base("Custom Toolbar") { } protected override void AddItems(NCommandBarItemCollection items) { // Add the "Add Appointment" button items.Add(CreateButton(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVy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MMTUsMHp6IiBmaWxsPSIjN0I3QjdCIiAvPg0KCQkJPHBhdGggZD0iTTAsNkwyMiw2TDIyLDFMMTgsMUwxOCw0TDE0LDRMMTQsMUw4LDFMOCw0TDQsNEw0LDFMMCwxenoiIGZpbGw9IiM5MDcwQjEiIC8+DQoJCQk8cGF0aCBkPSJNMCwyMkwxMSwyMkwxMSwyMC41TDkuNSwyMC41TDkuNSwyMEwyLDIwTDIsNkwwLDZ6TTIwLDkuNUwyMC41LDkuNUwyMC41LDExTDIyLDExTDIyLDZMMjAsNnp6IiBmaWxsPSIjN0I3QjdCIiAvPg0KCQkJPHBhdGggZD0iTTEwLDE0LjVMMTQsMTQuNUwxNCwxMUwxMCwxMXpNMTMsMTJMMTMsMTRMMTEsMTRMMTEsMTJ6eiIgZmlsbD0iI0NCNTI1RCIgLz4NCgkJCTxwYXRoIGQ9Ik0xMSwxNEwxMywxNEwxMywxMkwxMSwxMnp6IiBmaWxsPSIjQ0I1MjVEIiBvcGFjaXR5PSIwLjMiIC8+DQoJCTwvZz4NCgkJPGcgaWQ9Im92ZXJsYXkiPg0KCQkJPHBvbHlnb24gcG9pbnRzPSIxNiwyNCAxNiwxOSAxMSwxOSAxMSwxNiAxNiwxNiAxNiwxMSAxOSwxMSAxOSwxNiAyNCwxNiAyNCwxOSAxOSwxOSAxOSwyNCIgZmlsbD0iIzUyQjI1MCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgLz4NCgkJPC9nPg0KCTwvZz4NCjwvc3ZnPg0K")), NScheduleView.AddAppointmentCommand)); // Add the custom command button items.Add(CreateButton(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABsElEQVR4AYWTQ7BjQRSGZz3cjM04Y9u2bdu2bdu29bx83jxzvI79z+munDiVW/Vd/Lf/g0aF0MvyeUJT4ipRTsDLb+ImoQ4zhJifEYjBp2jmfAJWAsmTYP/mN9m+SE08WfsVar7PZuPHcajfRI2M68NFEGn6+3wM6jZSovTRyMAgH9jcgDM5v0/E5+ODUbOBCgeX9oAnfiLccRNxf1c/qV3Z1Ed+B7SjFQHOsiAyplHmSjUUuLZZDoYMemKw1F4eHAjX96AAt7l3MIifIDOZP/k1D5kubuxDCcazxvwTAZyBoouyImUykDCJmMjISeTyA+EAbMbjvf1xaFlP7FrYHTvmS7B7UQ+cWNULj/f0o5bCA+Tyh8jSTKFGU4UGzZXBNCOtWm2FrCYgwB8R4DQL4ue2ud3QpLkGOp0uiGYUZM6YDkDipMAAN0WAOgQYN5XYv0crNGyqhoJMCpUGjZqp0am9HuaP42H9EtRCC94LN1m0EkiahDeHB2LNjC5YOaUzHu3uL6uzBZtfhe7G7KDV+M4rEHH2i0KPQlAlMXga60TW8U5sHuEkXEQBcYFoGDr+P5RkQoMvtntjAAAAAElFTkSuQmCC")), CustomCommand)); } } public class CustomCommandAction : NScheduleCommandAction { #region Constructors /// /// Default constructor. /// public CustomCommandAction() { } /// /// Static constructor. /// static CustomCommandAction() { CustomCommandActionSchema = NSchema.Create(typeof(CustomCommandAction), NScheduleCommandAction.NScheduleCommandActionSchema); } #endregion #region Public Overrides /// /// Gets the command associated with this command action. /// /// public override NCommand GetCommand() { return CustomCommand; } /// /// Executes the command action. /// /// /// public override void Execute(NNode target, object parameter) { NScheduleView scheduleView = GetView(target); NMessageBox.Show("Schedule Custom Command executed!", "Custom Command", ENMessageBoxButtons.OK, ENMessageBoxIcon.Information); } #endregion #region Schema /// /// Schema associated with CustomCommandAction. /// public static readonly NSchema CustomCommandActionSchema; #endregion } #endregion } }

Download a fully functional C# (.cs) Command Bars Customization Example for Blazor Solution