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

Edited Issue: TimePicker fails with custom CultureInfo.DateTimeFormat.ShortDatePattern set [20834]

$
0
0
I am using the DatePicker control and it is failing when I use a custom ShortDateFormat string and try typing a value into the field.

To reproduce, create an empty WPF (I have tried targeting both .NET 4.5 and .NET 4.5.1) application and add a reference to v2.1 of the community edition.

In the App class (App.xaml.cs), add the following (you will also need to add namespace references)...

```
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);

CultureInfo cultureInfo = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
cultureInfo.DateTimeFormat.ShortDatePattern = "ddd dd/MM/yyyy";
Thread.CurrentThread.CurrentCulture = cultureInfo;

}
```

In MainWindow.xaml, replace the markup with the following...

```
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:et="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>

<et:TimePicker Grid.Column="2"
Grid.Row="2"
Height="24"
ShowButtonSpinner="False"
TimeInterval="00:15" />

</Grid>

</Window>
```

Now run the application and, in the TimePicker control, start typing a time ("12:00" for example); the "1" and "2" are accepted, but when you type the colon the application crashes...

"An item with the same key has already been added."
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Xceed.Wpf.Toolkit.DateTimeParser.<>c__DisplayClass3.<GetDateParts>b__2(String item)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Xceed.Wpf.Toolkit.DateTimeParser.GetDateParts(DateTime currentDate, CultureInfo cultureInfo)
at Xceed.Wpf.Toolkit.DateTimeParser.ComputeDateTimeString(String dateTime, String format, DateTime currentDate, CultureInfo cultureInfo)
at Xceed.Wpf.Toolkit.DateTimeParser.TryParse(String value, String format, DateTime currentDate, CultureInfo cultureInfo, DateTime& result)
at Xceed.Wpf.Toolkit.DateTimeUpDown.TryParseDateTime(String text, DateTime& result)
at Xceed.Wpf.Toolkit.DateTimeUpDown.IsCurrentValueValid()
at Xceed.Wpf.Toolkit.DateTimeUpDown.OnPreviewKeyDown(KeyEventArgs e)
at System.Windows.UIElement.OnPreviewKeyDownThunk(Object sender, KeyEventArgs e)
at System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(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.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.Interop.HwndSource.OnPreprocessMessage(Object param)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
at System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg, Boolean& handled)
at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at WpfApplication1.App.Main() in c:\Users\martin.robins\Documents\Visual Studio 2013\Projects\WpfApplication1\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

A similar error is emitted if you remove the XAML that disables the spinner and then run the application and simply click one of the spinner buttons twice.
Comments: ** Comment from web user: BoucherS **

Hi,

This issue will be fixed in v2.3.

In the meantime, you go in file : Xceed.Wpf.Toolkit/DateTimeUpDown/Implementation/DateTimeParser.cs
In method : GetDateParts
and replace the following line :
```
dateParts.Add( key, value );
```
by
```
if( !dateParts.ContainsKey( key ) )
{
dateParts.Add( key, value );
}
```


Viewing all articles
Browse latest Browse all 4964

Trending Articles



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