Formatting RadDateTimePicker

7 posts, 0 answers
  1. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 13 Mar 2015 Link to this post

    I am very confused about RadDateTimePickers formatting behavior. When we set DateSelectionMode to Year, why does it still create a complete date with the selected year but also with day/month from todays date?! This makes absolutely no sense to me. It should display the year only cause that's what my users select - a year, not a full date.

    Searching the forums I found several posts showing that we can set a new Culture to define custom ShortDatePattern and LongDatePattern. I did this and changed both formats to "yyyy". Now the control is displaying the year only (yeeha!) but it seems this format is not correct date Format for RadDateTimePickers parser. Checking the ParseDateTime event I can see that e.IsParsingSuccessful is always false now.

    So here's the question: How to select a year (yyyy) or month & year (mm/yyyy), display exactly what I've selected in the control's input box AND parse this value as a correct date in code behind?
  2. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 13 Mar 2015 Link to this post

    This can be reproduced with your XAML SDK solution "DateTimePicker_WPF" and project "StringFormatMVVM_WPF".

    Simply set ShortDatePattern from "dd.MM.yy" to "yyyy". Selecting a year from DropDown is still possible but entering a year manually (and that's what our users will do) results in an error.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 17 Mar 2015 Link to this post

    Hello Johannes,

    When displaying and selecting only years in RadDateTimePicker the ParseExact property needs to be set to True:
    <telerik:RadDatePicker ParseExact="True" x:Name="Picker" DateSelectionMode="Year" />

    Hopes this helps.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 18 Mar 2015 in reply to Nasko Link to this post

    Thanks for your reply but this does not help.

    When I enter 2 digits "15" the fields value becomes "2015" - that's nice. But when I enter 4 digits the ToolTip is displaying "Error". On LostFocus validation comes into place and the field becomes empty. It doesn't matter if ParseExcat is true or false - you can not enter a year with 4 digits.
  6. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 18 Mar 2015 Link to this post

    Hi Johannes,

    We were not able to observe the described behavior after setting ParseExact = "True" - please, check the attached video and let me know if there is something we missed. Also, please notice that if you didn't set the InputMode property to "DatePicker" and enter just an year without a time the parsing won't work again. However, if that is not the case please capture and send us a video with the observed by you behavior - it will be of great help in our further investigation?

    We're looking forward to hearing from you.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 18 Mar 2015 in reply to Nasko Link to this post

    Thanks for your video. It seems that this is working as long as I set ShortDatePattern and LongDataPattern both to "yyyy".

    Now please take a look at my Video (see link below). My target is to have ShortDatePattern "yy" and LongDatePattern "yyyy". It looks like RadDatePicker is always using ShortDatePattern for parsing, no matter if DisplayFormat is Short or Long. Shouldn't the parser use LongDatePattern if DisplayFormat is Long and ShortDatePattern if DisplayFormat is Short?

    http://www.screencast.com/t/gZ7ByzsqB7
  8. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 19 Mar 2015 Link to this post

    Hello Johannes,

    The observed by you behavior of RadDateTimePicker is an expected one. The control parses the entered value only by the set ShortDatePatern - if you try to enter the date in the format set to LongDatePattern, it will not be parsed. The date could not be parsed by both ShortDatePattern and LongDatePattern - you could use the LongDatePattern in order to visualize the date differently using the DisplayFormat property but if you try to modify it that won't be accepted.

    However, what we could suggest you for you scenario is to implement a custom parsing which will accept both formats. Please, check this article from our help documentation that will provide you a detailed information how to achieve this:
    http://docs.telerik.com/devtools/wpf/controls/raddatetimepicker/how-to/implement-custom-parsing.html

    Hopes this information will help you.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready