DOT

VVM

 DOCS

Version: 1.0 | 1.1 |

Calendar

in namespace DotVVM.BusinessPack.Controls

Renders a Calendar control which lets the user to select a date.

Properties

Name Type Description Notes Default Value
Attributes Dictionary<String,Object>
attribute
inner element
static value
bindable
default
ClientIDMode ClientIDMode Gets or sets the client ID generation algorithm.
attribute
inner element
static value
bindable
default
Static
DataContext Object Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value.
attribute
inner element
static value
bindable
default
Enabled Boolean Gets or sets whether the control is enabled and can be modified.
attribute
inner element
static value
bindable
default
True
ID String Gets or sets the unique control ID.
attribute
inner element
static value
bindable
default
InnerText String Gets or sets the inner text of the HTML element.
attribute
inner element
static value
bindable
default
MaxDate DateTime? Gets or sets the highest date that can be selected by user.
attribute
inner element
static value
bindable
default
MinDate DateTime? Gets or sets the lowest date that can be selected by user.
attribute
inner element
static value
bindable
default
Mode CalendarMode Gets or sets whether you want the user to pick only date, only time, or both date and time.
attribute
inner element
static value
bindable
default
Date
Restrictions IEnumerable<CalendarRestrictionBase> Gets or sets days a collection of rules specifying which date time intervals can't be selected.
attribute
inner element
static value
bindable
default
SelectedDate DateTime? Gets or sets the date selected by user.
attribute
inner element
static value
bindable
default
Visible Boolean Gets or sets whether the control is visible.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description
SelectionCompleted Command Gets or sets the command that is called when the user successfully selects or unselects a value.

Usage & Scenarios

Renders a Gregorian-style calendar control which lets the user to select a date, time or date and time values.

HTML Rendered by the Control

Sample 1: Basic Usage

The SelectedDate property represents a DateTime value with a date selected in the control.

<bp:Calendar SelectedDate="{value: SelectedDate}" />

<p>Selected date: <dot:Literal Text="{value: SelectedDate}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Calendar.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime SelectedDate { get; set; } = DateTime.Now;
    }
}

Sample 2: Selection Bounds

You can use the MinDate and MaxDate properties to specify the minimum and maximum values for the selection.

<bp:Calendar SelectedDate="{value: SelectedDate}"
             MinDate="{value: MinimumDate}"
             MaxDate="{value: MaximumDate}" />

<p>Selected date: <dot:Literal Text="{value: SelectedDate}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Calendar.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime SelectedDate { get; set; } = DateTime.Now;
        public DateTime MinimumDate { get; set; } = DateTime.Now.AddDays(-5);
        public DateTime MaximumDate { get; set; } = DateTime.Now.AddDays(5);
    }
}

Sample 3: Modes

You can use the Mode property to determine whether you want to select Date, Time or DateTime (a combination of date and time).

Even if you are in the Time mode, the control still requires the SelectedDate property to be bound to a property of DateTime type.

<bp:Calendar SelectedDate="{value: SelectedDate}"
             Mode="Date" />

<bp:Calendar SelectedDate="{value: SelectedTime}"
             Mode="Time" />

<bp:Calendar SelectedDate="{value: SelectedDateTime}"
             Mode="DateTime" />
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Calendar.sample3
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime SelectedDate { get; set; } = DateTime.Now;
        public DateTime SelectedTime { get; set; } = DateTime.Now;
        public DateTime SelectedDateTime { get; set; } = DateTime.Now;
    }
}

Sample 4: Restrictions

If you require more granular control over what dates can be selected, you can use the Restrictions property. We currently support the following types of restrictions:

  • DayOfWeekRestriction - Allows to disable selection of a specific day of week. You can also specify the time interval you need to disable using the StartTime and EndTime properties.
  • DateRangeRestriction - Allows to disable a secific range of dates (one day, one month, etc.). You just need to set the StartDate and EndDate properties.

Restrictions can be combined with MinDate and MaxDate properties and are verified both on client-side and server-side.

<bp:Calendar SelectedDate="{value: SelectedDate}"
             Restrictions="{value: Restrictions}" />
using System;
using DotVVM.BusinessPack.Controls;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Calendar.sample4
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime SelectedDate { get; set; } = DateTime.Now;

        public List<CalendarRestrictionBase> Restrictions { get; set; } = new List<CalendarRestrictionBase>()
        {
            new DayOfWeekRestriction() { DayOfWeek = DayOfWeek.Saturday },
            new DayOfWeekRestriction() { DayOfWeek = DayOfWeek.Sunday },
            new DateRangeRestriction() { StartDate = DateTime.MinValue, EndDate = DateTime.Now }
        };
    }
}

Sample 5: SelectionCompleted Event

When the user completes or changes the selection, the SelectionCompleted event is triggered.

<bp:Calendar SelectedDate="{value: SelectedDate}"
             SelectionCompleted="{command: SelectionCompleted()}" />

<p>Date selection has changed {{value: DateSelectionsCount}} times.</p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Calendar.sample5
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime SelectedDate { get; set; } = DateTime.Now;
        public int DateSelectionsCount { get; set; }

        public void SelectionCompleted()
        {
            DateSelectionsCount++;
        }
    }
}

Suggestions


Help & Contribute

The documentation is maintained on GitHub.
We'll be happy if you edit the page and create a pull request.

Send message