Setting the Minimum and Maximum Calendar Dates
You can change the dates that calendar spans by setting the MinimumDate and MaximumDate properties in the designer, in XAML, and in code.
Note: Try to avoid avoid setting the MinDate and 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 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 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. Open the Window1.xaml.cs page.
2. Place the following code beneath the InitializeComponent() method:
'Set the minimum date
C1DateTimePicker1.MinDate = new DateTime(2008, 01, 01)
'Set the maximum date
C1DateTimePicker1.MaxDate = new DateTime(2012, 12, 31)
• C#
//Set the minimum date
c1DateTimePicker1.MinDate = new DateTime(2008, 01, 01);
//Set the maximum date
c1DateTimePicker1.MaxDate = new DateTime(2012, 12, 31);
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 to move the calendar back until you can no
longer go forward. Note that the calendar stops on January 2008.
|