Calendar Example for Blazor

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

Calendar Example for Blazor Description

This example demonstrates how to create and configure a calendar widget. Using the controls to the right you can modify various aspect of the calendar's appearance and behavior. NOV calendar is fully localizable, you can test how it looks for different cultures by selecting one from the cultures combo box on the right.


Calendar Example

C# Calendar Example Code for Nevron UserInterface for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Globalization;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Presentation;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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()
		{
			m_Calendar = new NCalendar();
			m_Calendar.HorizontalPlacement = ENHorizontalPlacement.Left;
			m_Calendar.VerticalPlacement = ENVerticalPlacement.Top;
			m_Calendar.SelectedDateChanged += OnCalendarSelectedDateChanged;
			return m_Calendar;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			stack.FillMode = ENStackFillMode.Last;
			stack.FitMode = ENStackFitMode.Last;

			NGroupBox groupBox = new NGroupBox("Culture:");
			stack.Add(groupBox);
			groupBox.Margins = new NMargins(0, 0, 0, 10);

			// add the cultures combo box
			string calendarCultureName = m_Calendar.CultureName ?? m_Calendar.CultureInfo.Name;
			NComboBox culturesCombo = new NComboBox();
			for (int i = 0; i < Cultures.Count; i++)
			{
				CultureInfo culture = Cultures[i];
				NComboBoxItem item = new NComboBoxItem(NCultureInfo.GetEnglishCultureName(culture));
				item.Tag = culture.Name;
				culturesCombo.Items.Add(item);

				if (culture.Name == calendarCultureName)
				{
					culturesCombo.SelectedIndex = i;
				}
			}

			culturesCombo.SelectedIndexChanged += OnCultureComboSelectedIndexChanged;
			groupBox.Content = culturesCombo;

			// add the property editors
			NList editors = NDesigner.GetDesigner(m_Calendar).CreateMemberEditors(
				m_Calendar,
				NCalendar.EnabledProperty,
				NCalendar.HighlightTodayProperty,
				NCalendar.MonthFormatModeProperty,
				NCalendar.DayOfWeekFormatModeProperty);

			for (int i = 0; i < editors.Count; i++)
			{
				stack.Add(editors[i]);
			}

			// add the events log
			m_EventsLog = new NExampleEventsLog();
			stack.Add(m_EventsLog);

			return new NUniSizeBoxGroup(stack);
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create and configure a calendar widget. Using the controls to the right you can modify various aspect of the calendar's appearance and behavior. NOV calendar is fully localizable, you can test how it looks for different cultures by selecting one from the cultures combo box on the right.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Date Time Box", "https://www.nevron.com/docs/openvision/ui-date-time-box.html"), ("Drop Down Edits Overview", "https://www.nevron.com/docs/openvision/ui-drop-down-edits-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnCalendarSelectedDateChanged(NValueChangeEventArgs args) { DateTime date = (DateTime)args.NewValue; m_EventsLog.LogEvent("Selected Date Changed: " + date.ToString("d", m_Calendar.CultureInfo)); } private void OnCultureComboSelectedIndexChanged(NValueChangeEventArgs args) { NComboBox combo = args.TargetNode as NComboBox; NComboBoxItem selectedItem = combo.SelectedItem; if (selectedItem == null) return; m_Calendar.CultureName = (string)selectedItem.Tag; } #endregion #region Fields private NCalendar m_Calendar; private NExampleEventsLog m_EventsLog; #endregion #region Static Methods #endregion #region Constants private static readonly NList Cultures; #endregion #region Nested Types private class NCultureNameComparer : IComparer { public int Compare(CultureInfo culture1, CultureInfo culture2) { string englishName1 = NCultureInfo.GetEnglishCultureName(culture1); string englishName2 = NCultureInfo.GetEnglishCultureName(culture2); return englishName1.CompareTo(englishName2); } } #endregion } }

Download a fully functional C# (.cs) Calendar Example for Blazor Solution

Related Documentation Links