Setting the Minimum and Maximum Calendar Dates
In This Topic
You can change the dates that calendar spans by setting the and 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:
- Click the C1DateTimePicker control once to select it.
- In the Properties window, set the following properties:
- Set the MinDate property to 01/01/2008.
- Set the MaxDate property to 12/31/2012.
- Run the program.
- Click date picker drop-down button to expose the calendar.
- Click the forward button to move the calendar ahead until you can no longer go forward. Note that the calendar stops on December 2012.
- Click the back button 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:
- 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" />
- Run the program.
- Click date picker drop-down button to expose the calendar.
- Click the forward button to move the calendar ahead until you can no longer go forward. Note that the calendar stops on December 2012.
- Click the back button 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:
- Add x:Name="C1DateTimePicker1" to the <c1datetime: C1DateTimePicker> tag so that the control will have a unique identifier for you to call in code.
- Open the Window1.xaml.cs page.
- 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);
|
- Run the program.
- Click date picker drop-down button to expose the calendar.
- Click the forward button to move the calendar ahead until you can no longer go forward. Note that the calendar stops on December 2012.
- Click the back button to move the calendar back until you can no longer go forward. Note that the calendar stops on January 2008.