EnumListBox => System.InvalidCastException: Specified cast is not valid.

Editors for WPF Forum

The latest build of this product (v24.1.3) was released 1 month ago, which was before this thread was created.
Posted 19 days ago by Andrea
Version: 20.1.1
Avatar

Hello, 

I'm trying to use your EnumListBox to make a weekday picker but keep getting a cast error when I try to click on a day. 

             xmlns:tasksch="clr-namespace:Microsoft.Win32.TaskScheduler;assembly=Microsoft.Win32.TaskScheduler"

...            

            <editors:EnumListBox x:Name="daysOfTheWeekListBox"
                                 EnumType="{x:Type tasksch:DaysOfTheWeek}" 
                                 EnumValue="{Binding SelectedDaysOfWeek}"
                                 HorizontalAlignment="Left" VerticalAlignment="Top"
                                 Width="200" Height="300"
                                 SelectionMode="Multiple"
                                 >
            </editors:EnumListBox>
       public object SelectedDaysOfWeek { get; set; } // had also tried using the enum for the type



The picker shows perfectly in the loaded GUI but as soon as I click I get the following error:

System.InvalidCastException: Specified cast is not valid.
   at ActiproSoftware.Windows.Controls.Editors.EnumListBox.JJh(Object  )
   at ActiproSoftware.Windows.Controls.Editors.EnumListBox.IJ4(Object  , SelectionChangedEventArgs  )
   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.Controls.ListBox.OnSelectionChanged(SelectionChangedEventArgs e)
   at System.Windows.Controls.Primitives.Selector.SelectionChanger.End()
   at System.Windows.Controls.Primitives.Selector.SetSelectedHelper(Object item, FrameworkElement UI, Boolean selected)
   at System.Windows.Controls.Primitives.Selector.NotifyIsSelectedChanged(FrameworkElement container, Boolean selected, RoutedEventArgs e)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.Controls.ListBoxItem.OnSelected(RoutedEventArgs e)
   at System.Windows.Controls.ListBoxItem.OnIsSelectedChanged(DependencyObject d, 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 ActiproSoftware.Windows.Controls.Editors.EnumListBoxItem.jJj(Object  , InputPointerButtonEventArgs  )
   at ActiproSoftware.Windows.Input.InputAdapter.YIP(Object  , InputEventArgs  , InputPointerButtonKind  )
   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.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   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)

Comments (1)

Answer - Posted 18 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thank you for writing.  From looking at that assembly, the enum seems to be based on Int16 and some comparison logic in our code didn't handle that type properly.  We've fixed the bug for the next maintenance release.  A workaround would be to use any Int32 or Int64-based enumeration instead for now.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.