Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: DateTimePicker with custom format auto increments when focus is changed [21188]

$
0
0
This bug is found in the community edition of Extended WPF Toolkit atleast since version 2.0. The bug itself is in the _DateTimePicker_-control.

__Description__
When the format of an _DateTimePicker_ is custom set to the _FormatString="yyyy-MM-ddTHH:mm:ssZ"_ and the user changes focus between _DateTimePicker_-controls, the previous focused control auto increments it's hour with 2.

__How to reproduce__
1. Run the code underneath
2. Fill in the two _DateTimePicker_-controls with a (random) date
3. Tab between/or change focues between the two controls
-> The datetime will be auto-incremented.

_Code:_

``` XAML
<Window x:Class="WpfApplicationDateTimePickerTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Label Grid.Row="0" Grid.Column="0">
Timepicker 1
</Label>
<xctk:DateTimePicker Grid.Row="0" Grid.Column="1" x:Name="Dtck1" Width="200"
Format="Custom" FormatString="yyyy-MM-ddTHH:mm:ssZ" TextAlignment="Left">
</xctk:DateTimePicker>
<Label Grid.Row="1" Grid.Column="0">
Timepicker 2
</Label>
<xctk:DateTimePicker Grid.Row="1" Grid.Column="1" x:Name="Dtck2"
Format="Custom" FormatString="yyyy-MM-ddTHH:mm:ssZ" TextAlignment="Left">

</xctk:DateTimePicker>
</Grid>
</Window>
```
Comments: ** Comment from web user: emartin **

I found the issue.
The handling of "Z" in .net seems to be a bit "special":

http://stackoverflow.com/questions/833102/wheres-the-datetime-z-format-specifier

What cause the increment, is that when the text is parsed, it is interpreted has Zulu (Utc) time, (which it is your intention anyway), but when it come to convert the datetime to string, the "ToString" call just write the local time and add the "Z" at the end just like it would with some random character.

To avoid such problems, I would suggest to use the standard "u" format that is quite similar to yours. (except for the "T").

<xctk:DateTimePicker Format="Custom" FormatString="u"/>

Has about how to fix that..... I just don't want to get into "checking" the format string and handle all the possible issues (like the "Z"). Microsoft did the job in DateTime.Parse, re-inventing the wheel would be an endless source of bugs... The eventual solution would be to add some "Kind" property to the DateTimePicker to specified the intended date kind.


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>