Ticket T1283118
Visible to All Users

Use ISO 8601 for week numbers in DateEdit

created 6 months ago

Hi DevExpress,

your DateEdit control shows week numbers in the popup selector. From what I learned (correct me if I'm wrong), you're using Calendar.GetWeekOfYear() function for that. Is there a way how to switch to ISOWeek.GetWeekOfYear()?

I found T198732, but it's an old issue and you suggested to set FirstDayOfWeek = DayOfWeek.Monday and CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek. But it's not enough, since it still provides different results than ISOWeek.GetWeekOfYear() in some cases.

Thanks.

Kind regards
Peter

Answers approved by DevExpress Support

created 6 months ago

Hello,

Thank you for this detailed description and for your suggestion.

The ISOWeek class is available only for .NET, while our controls support both .NET and .NET Framework. To maintain support for both these frameworks, we have to continue using classes available everywhere.
Still, our developers are aware of such inquiries. Although I cannot promise these changes in the near future, we continue collecting similar inquiries to see the demand for this modification.

I searched for possible ways to override related classes in our controls, but unfortunately, the related methods are internal and I do not see ways to override them. The only idea that I have is to override related theme resources and manually calculate week numbers for the corresponding UI element. To be more precise, you will need to find the corresponding theme resource and override its implementation. We described the main idea of this technique in the following help topic: Modify Theme Resources. The target resource's theme key is DateNavigatorThemeKey ResourceKey=CalendarContentControlMonthTemplate.

For your convenience, I created a simple sample with a very basic implementation. Please refer to the attachment.

Note that this implementation is not a final solution - you will need to adjust it according to your needs and maintain it in the future on your own.

Regards,
Andrey

    Comments (2)

      Hi Andrey,

      thank you for your answer. I understand that you still have to support also "old" .NET Framework. Your solution with overriding theme resources seems to work fine. I just had to do some small tweaks.

      For anybody interested in a solution:
      The implementation in the sample is really just a sample and won't work properly if month doesn't spread across 6 weeks. To get proper date range for computing week numbers I used items (days) already existing in DateNavigatorCalendarContentControl. I hope that's ok and it won't have any side effects that I don't see right now ;-)

      Here is my modified converter (could be further simplified to IValueConverter):

      Visual Basic
      Imports System.Globalization Imports System.Windows.Markup Imports DevExpress.Xpf.Editors.DateNavigator.Controls Namespace UI.Converters Public Class DateEditWeekNumberConverter Inherits MarkupExtension Implements IMultiValueConverter Public Overrides Function ProvideValue(serviceProvider As IServiceProvider) As Object Return Me End Function Public Function Convert(values As Object(), targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IMultiValueConverter.Convert If values Is Nothing OrElse Not values.Length = 3 OrElse TypeOf values(2) IsNot DateNavigatorCalendarContentControl Then Return Nothing End If Dim ctrl = DirectCast(values(2), DateNavigatorCalendarContentControl) Dim items = ctrl.ItemsSource?.OfType(Of DateNavigatorCalendarCellViewModel).ToList() If items Is Nothing OrElse Not items.Any() Then Return Nothing End If Return items.GroupBy(Function(x) ISOWeek.GetWeekOfYear(x.DateTime)). ' NOTE: do not use Distinct; GroupBy preserves source order, Distinct might not Select(Function(x) x.Key). ToList() End Function Public Function ConvertBack(value As Object, targetTypes As Type(), parameter As Object, culture As CultureInfo) As Object() Implements IMultiValueConverter.ConvertBack Throw New NotImplementedException() End Function End Class End Namespace
      XAML
      <ItemsControl x:Name="PART_WeekNumbersItemsControl" Visibility="{Binding Path=(dxedn:DateNavigator.Navigator).ShowWeekNumbers, RelativeSource={RelativeSource Self}, Converter={StaticResource BoolToVisibilityConverter}}" Grid.Row="2" Grid.Column="0"> <ItemsControl.ItemsSource> <MultiBinding Converter="{StaticResource DateEditWeekNumberConverter}"> <Binding Path="DateTime" RelativeSource="{RelativeSource AncestorType=dxednc:DateNavigatorCalendarContentControl}"/> <Binding Path="WeekNumbers" RelativeSource="{RelativeSource AncestorType=dxednc:DateNavigatorCalendarContentControl}"/> <Binding Path="" RelativeSource="{RelativeSource AncestorType=dxednc:DateNavigatorCalendarContentControl}"/> </MultiBinding> </ItemsControl.ItemsSource> ... </ItemsControl>

      Kind regards
      Peter

      Andrey Marten (DevExpress Support) 6 months ago

        Hello Peter,

        Thank you for your understanding - I really appreciate it. I would like to emphasize that we keep all such inquiries in mind and think of ways to enhance DateEdit's behavior in this regard. Perhaps we will be able to at least rework the inner classes so that the related methods are implemented virtually. This way, it will be possible to accomplish the task without overriding theme resources.

        I also want to thank you for sharing the modifications you used in your own implementation. They indeed will be helpful for other customers.

        Feel free to contact us if you have other questions.

        Regards,
        Andrey

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.