wpftoolkit icon indicating copy to clipboard operation
wpftoolkit copied to clipboard

TimeSpanUpDown throws FormatException if e.g. the hour part is deleted (v3.2.0)

Open HaeusslerK opened this issue 7 years ago • 15 comments

XAML: <UserControl ... xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" ...> ... <xctk:TimeSpanUpDown UpdateValueOnEnterKey="True"/> ...

If e.g. the hour part is deleted a FormatException is thrown (Trace from my logs):

Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at Xceed.Wpf.Toolkit.TimeSpanUpDown.OnTextChanged(String previousValue, String currentValue) at Xceed.Wpf.Toolkit.Primitives.InputBase.OnTextChanged(DependencyObject o, 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, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at Xceed.Wpf.Toolkit.Primitives.UpDownBase`1.TextBox_TextChanged(Object sender, TextChangedEventArgs e) at System.Windows.Controls.TextChangedEventArgs.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.RaiseEvent(RoutedEventArgs e) at Xceed.Wpf.Toolkit.AutoSelectTextBox.OnTextChanged(TextChangedEventArgs e) at System.Windows.Controls.Primitives.TextBoxBase.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e) at System.Windows.Controls.TextBox.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e) at System.Windows.Documents.TextContainerChangedEventHandler.Invoke(Object sender, TextContainerChangedEventArgs e) at System.Windows.Documents.TextContainer.EndChange(Boolean skipEvents) at System.Windows.Documents.TextContainer.System.Windows.Documents.ITextContainer.EndChange(Boolean skipEvents) at System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents) at System.Windows.Documents.TextRange.System.Windows.Documents.ITextRange.EndChange(Boolean disableScroll, Boolean skipEvents) at System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose() at System.Windows.Documents.TextEditorTyping.OnDelete(Object sender, ExecutedRoutedEventArgs args) at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e) at System.Windows.Input.CommandManager.ExecuteCommandBinding(Object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding) at System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute) at System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e) at System.Windows.UIElement.OnExecutedThunk(Object sender, ExecutedRoutedEventArgs e) at System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target) 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.RoutedCommand.ExecuteImpl(Object parameter, IInputElement target, Boolean userInitiated) at System.Windows.Input.RoutedCommand.ExecuteCore(Object parameter, IInputElement target, Boolean userInitiated) at System.Windows.Input.CommandManager.TranslateInput(IInputElement targetElement, InputEventArgs inputEventArgs) at System.Windows.UIElement.OnKeyDownThunk(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.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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, 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.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled) at System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg, Boolean& handled) at System.Windows.Interop.ThreadMessageEventHandler.Invoke(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.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at VoltDelta.Workstation.WS.Workstation.App.Main() at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssemblyByName(String assemblyName, String[] args) at System.AppDomain.ExecuteAssemblyByName(String assemblyName)

HaeusslerK avatar Nov 22 '17 15:11 HaeusslerK

Similar problem here, hope you can fix it :)

tommy025 avatar Nov 26 '17 13:11 tommy025

I fixed it by rolling back to v2.5.


Von: tommy025 [email protected] Gesendet: Sonntag, 26. November 2017 14:14:44 An: xceedsoftware/wpftoolkit Cc: Haeussler, Klaus; Author Betreff: Re: [xceedsoftware/wpftoolkit] TimeSpanUpDown throws FormatException if e.g. the hour part is deleted (v3.2.0) (#1226)

Similar problem here, hope you can fix it :)

You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/xceedsoftware/wpftoolkit/issues/1226#issuecomment-347007912, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Af3kV-Lw1VChEZXcslE2wx9nV3OAZgz6ks5s6WRDgaJpZM4QniHD. Volt Delta International GmbH, Landsberger Str. 110, D-80339 Muenchen Sitz: Muenchen, Amtsgericht Muenchen, HRB 156693, VAT-ID DE814437634 Managing Directors (Geschaeftsfuehrer): Ali Resa Soltani, Christopher Aye

HaeusslerK avatar Nov 26 '17 18:11 HaeusslerK

Hi,

This is already fixed in v3,4. You can get it at https://xceed.com/xceed-toolkit-plus-for-wpf/.

In the meantime, you can go in file Xceed.Wpf.Toolkit/TimeSpanUpDown/Implementation/TimeSpanUpDown.cs, In method OnTextChanged, Replace the condition : if( values.Count() >= 2 ) with: if( ( values.Count() >= 2 ) && !values.Any( x => string.IsNullOrEmpty( x ) ) )

XceedBoucherS avatar Nov 28 '17 12:11 XceedBoucherS

Nice, and a NuGet update would be appreciated!

tommy025 avatar Dec 03 '17 10:12 tommy025

Hi,

Nuget will be updated at the same time as the version will be released. Thanks.

XceedBoucherS avatar Dec 04 '17 12:12 XceedBoucherS

When will you release this version? I don't want to roll back to the previous version and now I'm wondering if I should either create a local fork of the toolkit and fix the issue myself or if I should wait for the updated NuGet package

michaelkollmann avatar Dec 19 '17 11:12 michaelkollmann

Hi, Toolkit Plus v3.6 will be release in beginning of 2018. At around the same time, Toolkit Community v3.3 should be released on GitHub. v3.4 Toolkit Community should be released later during 2018. Toolkit Community is always 2-3 versions behind the Toolkit Plus. You can get Toolkit Plus here : https://xceed.com/xceed-toolkit-plus-for-wpf/ Thanks.

XceedBoucherS avatar Dec 19 '17 12:12 XceedBoucherS

I have a simillar issue in 3.7.0

Norja avatar Dec 22 '19 09:12 Norja

Hi, In v3.7, when UpdateValueOnEnterKey is False and deleting the hour part, you shouldn't see a FormatException. An assertion failed should be popped in Debug Mode(because the format is not filled), but no crash should happens.

When UpdateValueOnEnterKey is True and the content is empty, clicking on the up/down buttons could result in a NullRefException in TimeSpanUpDown.Increment() because the timePart,Content is null and the timePartContent.Length can't be obtained. This will be fixed in v4.0. You can also fix this by using timePart.Length instead of timePart.Content.Length in this situation. But again, an assertion failed should be popped in Debug Mode(because the format is not filled), but no crash should happens.

XceedBoucherS avatar Jan 06 '20 15:01 XceedBoucherS

This Zombie-Bug somehow returned in another form.

TheWhiteAmbit avatar Aug 17 '20 09:08 TheWhiteAmbit

Hi, can you give more detail if this bug is still present ? Thank you.

XceedBoucherS avatar Aug 26 '20 18:08 XceedBoucherS

(4.0.1) When a user is allowed to input text to the TimeSpanUpDown and the format is interrupted (e.g. deleting the hour part), this error is raised (even in a production version):

---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
Something went wrong when parsing TimeSpan.
---- Assert Long Message ----

   at Xceed.Wpf.Toolkit.TimeSpanUpDown.OnTextChanged(String previousValue, String currentValue)
   at Xceed.Wpf.Toolkit.Primitives.InputBase.OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)

Code:

<xctk:TimeSpanUpDown
    AllowTextInput="True"
    DefaultValue="00:01:00"
    Value="{Binding TimeDuration}"
    Maximum="2:00:00:00"
    Minimum="00:01:00"
    TextAlignment="Center" />

The null parts should behave as zeros instead of raising an error.

Frixs avatar Nov 30 '20 20:11 Frixs

Hi, Your idea of using "00" when a date part is removed is interesting, but it won't let you remove the date part to type a new one. We can always remove the Assert, but it should only happens when using a Debug version of Xceed Toolkit. Try compiling the Xceed Toolkit in Release mode and see if it happens.

XceedBoucherS avatar Dec 02 '20 12:12 XceedBoucherS

The problem is, that the assert will occure in Release Mode also. Think this is because the WPF Toolkit nuget is compiled in Debug mode? Really nasty problem .

For me, I solved it by doing a convert before calling the base method.

        #region Overrides of TimeSpanUpDown

        protected override void OnTextChanged(string previousValue, string currentValue)
        {
            currentValue = ConvertValueToText(ConvertTextToValue(currentValue));
            base.OnTextChanged(previousValue, currentValue);
        }

        #endregion

BitKFu avatar Dec 29 '20 18:12 BitKFu

Hi BitKFu, Toolkit v4.0.2 is now available. It should fix your problem. Thank you.

XceedBoucherS avatar Jan 07 '21 17:01 XceedBoucherS