Display Date Format

14 posts, 0 answers
  1. nbahl
    nbahl avatar
    25 posts
    Member since:
    Feb 2007

    Posted 18 Feb 2009 Link to this post

    Hi,
    Is there a way to format the display date, instead of mm/dd/yyyy I need to just display mm/yyyy.  I don't see the DisplayDateFormat property available in WPF, is there a way to do this?

    Thanks,
    Nate
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 23 Feb 2009 Link to this post

    Hello nbahl,

    First I want to apology for the late answer.
    You can set the culture property of RadDatePicker and customize the Culture ShortDatePattern property in order to change the date format.
    Here is a snippet changing the display date to MM/yyyy.

    CultureInfo cultureInfo = new CultureInfo("en-US");  
    DateTimeFormatInfo dateInfo = new DateTimeFormatInfo();  
    dateInfo.ShortDatePattern = "MM/yyyy";  
    cultureInfo.DateTimeFormat = dateInfo;  
    radDatePicker1.Culture = cultureInfo; 

    Let me know if you need more information.

    Sincerely yours,
    Hristo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WPF is Visual Studio 2017 Ready
  4. nbahl
    nbahl avatar
    25 posts
    Member since:
    Feb 2007

    Posted 23 Feb 2009 Link to this post

    Worked perfectly....thank you.
  5. nbahl
    nbahl avatar
    25 posts
    Member since:
    Feb 2007

    Posted 28 Apr 2009 Link to this post

    Hristo,

    I have run into a problem when using this code.  If I pick a date from the calendar it works perfectly, but if I type in a date I get an error "Object reference not set to an instance of an object".  Below is the stack trace if that helps.  I am on Q1 2009 release.  Also is there a way to create a shortcut for entering the current date? Ex. if a user enters "/" it defaults in todays date.

    Thanks!
    Nate Bahl


       at Telerik.Windows.Controls.DatePicker.DateTimeParsing.DateTimeEvaluator.GetFirstAvailablePosition(Token token, Dictionary`2 inputBuckets)
       at Telerik.Windows.Controls.DatePicker.DateTimeParsing.DateTimeEvaluator.Distribute(Token[] originalTokens)
       at Telerik.Windows.Controls.DatePicker.DateTimeParsing.DateTimeEvaluator.GetDate(Token[] tokens, DateTime date)
       at Telerik.Windows.Controls.DatePicker.DateTimeParsing.TripletEntry.Evaluate(DateTime currentDate, FormatInfo formatInfo)
       at Telerik.Windows.Controls.DatePicker.DateTimeParsing.DateTimeEntry.Evaluate(DateTime currentDate, FormatInfo formatInfo)
       at Telerik.Windows.Controls.RadDatePicker.ParseDateAndUpdateTextBox()
       at Telerik.Windows.Controls.RadDatePicker.OnInputBoxLostFocus(Object sender, RoutedEventArgs e)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.OnLostFocus(RoutedEventArgs e)
       at System.Windows.Controls.Primitives.TextBoxBase.OnLostFocus(RoutedEventArgs e)
       at System.Windows.UIElement.IsFocused_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.Controls.TextBox.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
       at System.Windows.DependencyObject.ClearValueCommon(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata)
       at System.Windows.DependencyObject.ClearValue(DependencyPropertyKey key)
       at System.Windows.Input.FocusManager.OnFocusedElementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at System.Windows.Input.FocusManager.SetFocusedElement(DependencyObject element, IInputElement value)
       at System.Windows.Input.KeyboardNavigation.UpdateFocusedElement(DependencyObject focusTarget)
       at System.Windows.FrameworkElement.OnGotKeyboardFocus(Object sender, KeyboardFocusChangedEventArgs e)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
       at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew)
       at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
       at System.Windows.UIElement.Focus()
       at System.Windows.Input.KeyboardNavigation.Navigate(DependencyObject currentElement, TraversalRequest request, ModifierKeys modifierKeys, DependencyObject firstElement)
       at System.Windows.Input.KeyboardNavigation.Navigate(DependencyObject sourceElement, Key key, ModifierKeys modifiers)
       at System.Windows.Input.KeyboardNavigation.ProcessInput(InputEventArgs inputEventArgs)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
       at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
       at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
       at System.Windows.Forms.Integration.ElementHost.ProcessCmdKey(Message& msg, Keys keyData)
       at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
       at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
       at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at WinFormTestControl.Program.Main() in C:\rccdev\utilnxt\net\BankReconcilation\WinFormTestControl\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  6. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 01 May 2009 Link to this post

    Hello Nate,

    It seems that there is a bug in the DateTime parser. It expects the day component of the date to always be there. We have logged this as an issue and it will be fixing it for the next SP or Q2 release.

    Your Telerik points have been updated for the bug report.

    As for your second question: you can register for the KeyDown event and change the date there, like so:

        datePicker.KeyDown += new KeyEventHandler(datePicker_KeyDown);  
     
    void datePicker_KeyDown(object sender, KeyEventArgs e)  
    {  
        if (e.Key == Key.Subtract)  
        {  
            var datePicker = sender as RadDatePicker;  
            datePicker.SelectedDate = DateTime.Now;  
            e.Handled = true;  
        }  


    All the best,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. James
    James avatar
    41 posts
    Member since:
    Jul 2007

    Posted 12 Jul 2009 Link to this post

    Is there any way to set the display date format using only XAML?
  8. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 14 Jul 2009 Link to this post

    Hi James,

     For now there is no way to set the format in XAML. You have to set it in code.

    All the best,
    Boyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. matt
    matt avatar
    2 posts
    Member since:
    Jun 2009

    Posted 27 Jul 2009 Link to this post

    The date picker parser problem mentioned above (null ref exception when using a date format without days) still exists in the q2 release.
  10. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 28 Jul 2009 Link to this post

    Hi matt,

    Yes, this is not fixed. We are reworking RadCalendar and RadDatepicker for Q3. We are making major structure changes of this two controls as  current implementation is not good enough and SL3 was released which gives the opportunity for some improvements. That's why we have frozen all fixes for the current implementation.
     Sorry for the inconvenience caused. You can expect improved version of this controls for Q3.

    Regards,
    Boyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  11. matt
    matt avatar
    2 posts
    Member since:
    Jun 2009

    Posted 29 Jul 2009 Link to this post

    If the controls are being reworked a simple way to make the date picker a month picker or a year picker would be good. I.e. Select a month and have that set the selected date to the first day of the month instead of drilling down into the day view. I have this working with the current control but it was not straight forward. It required a month template with a button and the click event can be handled etc. Even a click event on CalendarButton would be good and a way to cancel the default behaviour of drilling down to the day view. With a display format on the text box of MMM yyyy it would make a simple month picker. Currently we have to live with what feels like a hacky solution and a date format that includes the days. A way to disable the parser altogether would be good and I am guessing stop problems like the one in this thread if it is not required.
  12. Henrique Duarte
    Henrique Duarte avatar
    104 posts
    Member since:
    Oct 2003

    Posted 29 Jul 2009 Link to this post

    Hello matt,

    I'm waiting for this implementation too.
    I opened a support ticket for that with a sample code:

    private void RadDatePicker_DisplayModeChanging(object sender, CalendarModeChangedEventArgs e)     
    {     
        if (e.NewMode == DisplayMode.MonthView)     
        {     
            e.Cancel = true;     
            ((RadDatePicker)e.Source).SelectedDate = ((RadDatePicker)e.Source).Calendar.CurrentDate;     
        }     

    The are two problems:
    1 - They don't have *YET* a "DisplayModeChanging" method, only "DisplayModeChanged";
    2 - The Calendar is private, so we cannot access the CurrentDate.

    If we have luck, maybe this implementation will be on next build.

    Best regards,

    Henrique
  13. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 30 Jul 2009 Link to this post

    Hi Henrique Duarte,

    We appreciate you suggestion and will consider such features for the Q3 2009 release. Thanks once again.


    Sincerely yours,
    Kaloyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  14. Suman
    Suman avatar
    1 posts
    Member since:
    Dec 2011

    Posted 06 Jan 2014 Link to this post

    Hi,

    I have added your code snippet, but could not resolve. Can you send more details xaml and code.
    EG,

    CultureInfo cultureInfo = 
    new CultureInfo("en-US");  
    DateTimeFormatInfo dateInfo = new DateTimeFormatInfo();  
    dateInfo.ShortDatePattern = "MM/yyyy";  
    cultureInfo.DateTimeFormat = dateInfo;  
    radDatePicker1.Culture = cultureInfo; 


    Thanks
    Suman
  15. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 08 Jan 2014 Link to this post

    Hi Suman,

    Please check the following article which demonstrates how to set a custom date format to the RadDateTimePicker control:
    http://www.telerik.com/help/wpf/raddatetimepicker-features-formatting.html

    I hope this helps.

    Regards,
    Yana
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready