ComponentOne DateTimeEditors for WPF
DateTimePicker Overview / C1DateTimePicker Task-Based Help / Setting the Minimum and Maximum Calendar Dates
In This Topic
    Setting the Minimum and Maximum Calendar Dates
    In This Topic

    You can change the dates that calendar spans by setting the MinDate and MaxDate properties in the designer, in XAML, and in code.

    Note: Try to avoid avoid setting the C1DateTimePicker.MinDate and C1DateTimePicker.MaxDate properties in XAML as a string value. Parsing these values from strings is culture specific. If you set a value with your current culture and a user is using different culture, the user can get XamlParseException when loading your site. The best practice is to set these values from code or via data binding.

    In the Designer

    Complete the following steps:

    1. Click the C1DateTimePicker control once to select it.
    2. In the Properties window, set the following properties:
      • Set the MinDate property to 01/01/2008.
      • Set the MaxDate property to 12/31/2012.
    3. Run the program.
    4. Click date picker drop-down button to expose the calendar.

    5. Click the forward button to move the calendar ahead until you can no longer go forward. Note that the calendar stops on December 2012.
    6. Click the back button Calendar_Back.png to move the calendar back until you can no longer go forward. Note that the calendar stops on January 2008.

    In XAML

    Complete the following steps:

    1. Add MinDate="2008-01-01" and MaxDate="2012-12-31" to the <my:C1DateTimePicker> tag so that the markup resembles the following:
       <my:C1DateTimePicker Height="26" Name="c1DateTimePicker1" MinDate="2008-01-01" MaxDate="2012-12-31" />
      
    2. Run the program.
    3. Click date picker drop-down button to expose the calendar.

    4. Click the forward button  to move the calendar ahead until you can no longer go forward. Note that the calendar stops on December 2012.
    5. Click the back button Calendar_Back.png to move the calendar back until you can no longer go forward. Note that the calendar stops on January 2008

    In Code

    Complete the following:

    1. Add x:Name="C1DateTimePicker1" to the <c1datetime: C1DateTimePicker> tag so that the control will have a unique identifier for you to call in code.
    2. Open the Window1.xaml.cs page.
    3. Place the following code beneath the InitializeComponent() method:

      Visual Basic
      Copy Code
      'Set the minimum date
      C1DateTimePicker1.MinDate = new DateTime(2008, 01, 01)
      'Set the maximum date
      C1DateTimePicker1.MaxDate = new DateTime(2012, 12, 31)
      
      C#
      Copy Code
      //Set the minimum date
      c1DateTimePicker1.MinDate = new DateTime(2008, 01, 01);
      //Set the maximum date
      c1DateTimePicker1.MaxDate = new DateTime(2012, 12, 31);
      
    4. Run the program.
    5. Click date picker drop-down button to expose the calendar.

    6. Click the forward button to move the calendar ahead until you can no longer go forward. Note that the calendar stops on December 2012.
    7. Click the back button Calendar_Back.png to move the calendar back until you can no longer go forward. Note that the calendar stops on January 2008.