This project has moved. For the latest updates, please go here.

DateTimePicker Validation

Jan 17, 2014 at 1:01 PM
Edited Jan 17, 2014 at 1:02 PM
Hi,

I have a scenario I can't figure out how to implement.

I want to validate that from date is less than the to date. I am using the DateTimePicker control.
<StackPanel Orientation="Horizontal" Margin="5,2,5,2">
                                    <TextBlock Text="From Date: "  />
                                    <xctk:DateTimePicker x:Name="FromDatePicker"    
                                         AutoCloseCalendar="True"
                                         Width="200"
                                         VerticalAlignment="Center"
                                         HorizontalAlignment="Left"
                                        Value="{Binding FromDate, Mode=TwoWay}"
                                         Format="Custom"
                                         FormatString="dd-MMM-yy HH:mm"
                                         TimeFormat="Custom"
                                         TimeFormatString="HH:mm" 
                                         ToolTip="From Date">
                                    </xctk:DateTimePicker>

                                    <TextBlock Text="To Date: " />

                                    <xctk:DateTimePicker x:Name="ToDatePicker" 
                                         AutoCloseCalendar="True"
                                         Width="200"
                                         VerticalAlignment="Center"
                                         HorizontalAlignment="Left"
                                         Value="{Binding ToDate, Mode=TwoWay}"
                                         Format="Custom"
                                         FormatString="dd-MMM-yy HH:mm"
                                         TimeFormat="Custom"
                                         TimeFormatString="HH:mm" TimeWatermark="Please select time"
                                         ToolTip="To Date"/>
                                </StackPanel>
Can someone give me a hint on how to validate that the to date is greater than the from date?
Developer
Jan 17, 2014 at 6:26 PM
Hi,

In v2.1 of the Toolkit, which should be released pretty soon, you will have access to Minimum and Maximum property in DateTimePicker. You will be able to do something like :
<TextBlock Text="From Date: " />
      <xctk:DateTimePicker x:Name="FromDatePicker"
                           AutoCloseCalendar="True"
                           Width="200"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Left"
                           Value="{Binding FromDate, Mode=TwoWay}"
                           Format="Custom"
                           FormatString="dd-MMM-yy HH:mm"
                           TimeFormat="Custom"
                           TimeFormatString="HH:mm"
                           ToolTip="From Date"
                           Maximum="{Binding Value, ElementName=ToDatePicker}">
      </xctk:DateTimePicker>

      <TextBlock Text="To Date: " />

      <xctk:DateTimePicker x:Name="ToDatePicker"
                           AutoCloseCalendar="True"
                           Width="200"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Left"
                           Value="{Binding ToDate, Mode=TwoWay}"
                           Format="Custom"
                           FormatString="dd-MMM-yy HH:mm"
                           TimeFormat="Custom"
                           TimeFormatString="HH:mm"
                           TimeWatermark="Please select time"
                           ToolTip="To Date"
                           Minimum="{Binding Value, ElementName=FromDatePicker}"/>
Apr 3, 2014 at 12:30 PM
Hi Is the version 2.1 is released.
Developer
Apr 3, 2014 at 2:46 PM
Hi,
Yes v2.1 is released since February 20th. It is available here : https://wpftoolkit.codeplex.com/releases/view/106016