DelegateCommand (PRISM) & ToggleSwitch

2 posts, 0 answers
  1. Dmitry
    Dmitry avatar
    18 posts
    Member since:
    Aug 2008

    Posted 17 May 2012 Link to this post

    I am trying to implement the ToggleSwitch in my app and am using the PRISM DelegateCommand to write-up the Command Binding.

    XAML is fairly simple

    <tprim:RadToggleSwitch Command="{Binding Path=SomeDelegateCommand}" />

    In the code behind, i was under the impression that if no parameter binding is setup that it would pass a BOOL value as the parameter but instead upon trying to load the page with the switch it throws the exception below. Any ideas?

    Exception

    System.NullReferenceException was unhandled
      Message=NullReferenceException
      StackTrace:
           at Microsoft.Practices.Prism.Commands.DelegateCommand`1.<>c__DisplayClass6.<.ctor>b__3(Object o)
           at Microsoft.Practices.Prism.Commands.DelegateCommandBase.CanExecute(Object parameter)
           at Microsoft.Practices.Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.CanExecute(Object parameter)
           at Telerik.Windows.Controls.RadToggleSwitch.UpdateIsEnabledFromCommand()
           at Telerik.Windows.Controls.RadToggleSwitch.OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
           at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
           at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
           at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
           at System.Windows.Data.BindingExpression.RefreshExpression()
           at System.Windows.Data.BindingExpression.SendDataToTarget()
           at System.Windows.Data.BindingExpression.SourceAcquired()
           at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
           at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)
           at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)
           at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent, Byte bCanCreateParent)
           at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
           at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
           at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
           at Microsoft.Phone.Controls.PivotItem.MeasureOverride(Size availableSize)
           at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
           at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
           at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
           at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
           at Microsoft.Phone.Controls.Pivot.MeasureOverride(Size availableSize)
           at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
           at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
           at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
           at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
           at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
           at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
           at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
           at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
           at Microsoft.Phone.Controls.PhoneApplicationFrame.MeasureOverride(Size availableSize)
           at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 19 May 2012 Link to this post

    Hi Dmitry,

    Thank you for contacting us.

    This first time when the canExecuteMethod delegate is called its parameter is null and this causes the NullReferenceException. We are going to change this and the fix will be included in our internal build which will be released next week.

    As a temporary solution I'd suggest that you change the type of your DelegateCommand to bool? instead of bool. This will allow the parameter to be null in the beginning and no exception will be thrown. When the internal build is available, you can change it back to bool.

    Thank you for reporting this to us. I have added some telerik points to your account for you cooperation.

    Greetings,
    Todor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
Back to Top