Clear Displayed Date and Update Source

8 posts, 1 answers
  1. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 17 Mar 2014 Link to this post

    I am using a DatePicker as follows;

    <telerik:RadDatePicker Name="dtpPublished"
        Margin="2"  
        Grid.Row="2"
        Grid.Column="1"
        HorizontalAlignment="Left"
        HorizontalContentAlignment="Left"
        VerticalAlignment="Center"
        MinWidth="500"
        MaxWidth="500"
        DateTimeWatermarkContent="Leave blank or enter the date this Scenario was published"
        SelectedDate="{Binding Path=PublishedDt, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
    </telerik:RadDatePicker>

    In the code behind I am setting the Culture and date format as follows;

    With dtpPublished
        .Culture = New System.Globalization.CultureInfo("en-AU")
        .Culture.DateTimeFormat.ShortDatePattern = "d-MM-yyyy"
        .Culture.DateTimeFormat.ShortTimePattern = "hh:mm"
     
        .Culture.DateTimeFormat.LongDatePattern = "ddd, d MMM yyyy"
        .Culture.DateTimeFormat.LongTimePattern = "h:mm:ss tt"
     
        .DisplayFormat = Telerik.Windows.Controls.DateTimePickerFormat.Long
    End With

    My problem is if I clear the displayed date by pressing delete when the date text is highlighted I want the control to update the source as if a date wasn't entered.  Effectively it should set the source to Nothing or to Date.MinValue.  Even after I Tab off the control the source isn't updated?

    Preferably the control should display a blank entry rather than "1/01/0001" as the date.
  2. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 17 Mar 2014 in reply to Raymond Link to this post

    Anyone have any suggestions?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 18 Mar 2014 Link to this post

    Hi Raymond,

    The SelectedDate property of the DatePicker is of type nullable DateTime (DateTime?). So it should be bound to a nullable DateTime property in the ViewModel. Please check whether the PublishedDt is of the correct type as if so the PropertyChanged event should be raised when the selection of the DatePicker has been cleared.

    Hope this helps.

    Regards,
    Kalin
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  5. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 18 Mar 2014 in reply to Kalin Link to this post

    Hi Kalin,

    Thanks for getting back to me.

    I changed the PublishedDt property in my class to Date? and DateTime? and in both the cases the DateTimePicker does not display the date when selected from the calendar.  

    I can however enter the date from the keyboard and it raises a selection changed event.

    The attached files illustrate;
    1) The DTP before a selection is made from the calendar,
    2) Selecting "6 Mar 2014" from the calendar,
    3) The DTP after the date is selected,
    4) Manually entering a date with the "Culture" code removed, and
    5) Manually entering a date with the "Culture" code.

    I also just noted that if I enter the date manually then select the a date from the calendar it does not update the original date entered.

    I also tried commenting out the "Culture" code in case that was causing a problem.
  6. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013
  7. Answer
    Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 19 Mar 2014 Link to this post

    Hi Raymond,

    We are not able to reproduce the described issue. Could you please share some more detailed information about the exact scenario as well as the version of the controls you are using? However if you are able to isolate the issue in a sample project and send it to us that would be really helpful.

    I'm looking forward to hearing from you.

    Regards,
    Kalin
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  8. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 19 Mar 2014 in reply to Kalin Link to this post

    Hi Kalin,

    The problem turned out to be in my code.  The property was comparing the updated value with the backing variable which was nothing so the test failed.  After modifying the code to compare null values everything was OK.

    Thanks for your help.
  9. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 20 Mar 2014 Link to this post

    Hello Raymond,

    We are glad you have managed to resolve the issue.

    If you have any other questions let us know.

    Regards,
    Kalin
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready