Calendar Example for WPF

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

Calendar Example for WPF 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 WPF
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 WPF Solution

VB.NET Calendar Example Code for Nevron UserInterface for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.DataStructures
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Editors
Imports Nevron.Nov.Globalization
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System
Imports System.Collections.Generic
Imports System.Globalization

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 - NCalendarExample"

		' 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
            m_Calendar = New NCalendar()
            m_Calendar.HorizontalPlacement = ENHorizontalPlacement.Left
            m_Calendar.VerticalPlacement = ENVerticalPlacement.Top
            Me.m_Calendar.SelectedDateChanged += AddressOf OnCalendarSelectedDateChanged
            Return m_Calendar
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            stack.FillMode = ENStackFillMode.Last
            stack.FitMode = ENStackFitMode.Last

            Dim groupBox As NGroupBox = New NGroupBox("Culture:")
            stack.Add(groupBox)
            groupBox.Margins = New NMargins(0, 0, 0, 10)

            ' add the cultures combo box
            Dim calendarCultureName = If(m_Calendar.CultureName, m_Calendar.CultureInfo.Name)
            Dim culturesCombo As NComboBox = New NComboBox()
            For i = 0 To Cultures.Count - 1
                Dim culture = Cultures(i)
                Dim item As NComboBoxItem = New NComboBoxItem(NCultureInfo.GetEnglishCultureName(culture))
                item.Tag = culture.Name
                culturesCombo.Items.Add(item)

                If Equals(culture.Name, calendarCultureName) Then
                    culturesCombo.SelectedIndex = i
                End If
            Next

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

            ' add the property editors
            Dim editors = NDesigner.GetDesigner(m_Calendar).CreateMemberEditors(m_Calendar, NInputElement.EnabledProperty, NCalendar.HighlightTodayProperty, NCalendar.MonthFormatModeProperty, NCalendar.DayOfWeekFormatModeProperty)

            For i = 0 To editors.Count - 1
                stack.Add(editors(i))
            Next

            ' add the events log
            m_EventsLog = New NExampleEventsLog()
            stack.Add(m_EventsLog)

            Return New NUniSizeBoxGroup(stack)
        End Function
        Public Function GetExampleDescription() As String
            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.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("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")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnCalendarSelectedDateChanged(args As NValueChangeEventArgs) Dim [date] As Date = args.NewValue m_EventsLog.LogEvent("Selected Date Changed: " & [date].ToString("d", m_Calendar.CultureInfo)) End Sub Private Sub OnCultureComboSelectedIndexChanged(args As NValueChangeEventArgs) Dim combo As NComboBox = TryCast(args.TargetNode, NComboBox) Dim selectedItem = combo.SelectedItem If selectedItem Is Nothing Then Return m_Calendar.CultureName = CStr(selectedItem.Tag) End Sub #End Region #Region "Fields" Private m_Calendar As NCalendar Private m_EventsLog As NExampleEventsLog #End Region #Region "Static Methods" #End Region #Region "Constants" Private Shared ReadOnly Cultures As NList(Of CultureInfo) #End Region #Region "Nested Types" Private Class NCultureNameComparer Implements IComparer(Of CultureInfo) Public Function Compare(culture1 As CultureInfo, culture2 As CultureInfo) As Integer Implements IComparer(Of CultureInfo).Compare Dim englishName1 = NCultureInfo.GetEnglishCultureName(culture1) Dim englishName2 = NCultureInfo.GetEnglishCultureName(culture2) Return englishName1.CompareTo(englishName2) End Function End Class #End Region End Class

Download a fully functional VB.NET (.vb) Calendar Example for WPF Solution

Related Documentation Links