Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2030
Format xamDateTimeInput to show weeknumber
posted

Hello,

considering that it is possible to show the weeknumber in the calender control of the xamDateTimeInput I would like to know how I can show the weeknumber already in the xamDateTimeInput.

Please let me know if somebody already managed this.

Thanks

Niko

  • 34430
    Offline posted

    Hello Niko,

    Thank you for your post.

    I am currently unaware of a DateTime format that would allow you to show the week number in the XamDateTimeInput, but there are a couple of things you could try to accomplish this. Now, the first thing I would recommend is to actually have a look at the following stackoverflow article, as it shows how to get a week number from a particular DateTime object, and the methods shown on this post are used in the two following recommendations: http://stackoverflow.com/questions/16246786/get-week-number-and-year-as-yyyyww-from-current-date-ssis-script-task-plus-n-w.

    One recommendation that I can make is to create your own IValueConverter for usage with the ValueToDisplayTextConverter in the XamDateTimeInput. The converter's Convert method will fire when the Value property of the XamDateTimeInput changes. Knowing this, you can get the DateTime value from the parameters of your converter, and use the calendar.GetWeekOfYear method shown in the stackoverflow post above to create a string to show as the display text of your XamDateTimeInput. There is a bit of a caveat with this option though, in that the display text will only show when not in edit mode on the XamDateTimeInput.

    In my opinion, a better and perhaps more adventurous option of doing this would be to create a custom class deriving from XamDateTimeInput. Doing this would allow you to create your own DependencyProperty for the control and update this property on the ValueChanged event of that particular control. You would still need a way to show it, though, and so I would recommend inclusion of the default style for XamDateTimeInput, and modifying it to target your custom XamDateTimeInput. You can then modify the template of the control to show the week number off to either side of the MaskedInputTextBox that represents to the text editor inside of the XamDateTimeInput while in edit mode. This default style and its dependencies can be found inside of the generic.shared.xaml file commonly found at C:\Program Files (x86)\Infragistics\<your version here>\WPF\DefaultStyles\DateTimeInput.

    I have attached a sample project demonstrating both approaches. I hope it helps you.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XamDateTimeInputWeekNumberCase.zip