This is a migrated thread and some comments may be shown as answers.

DelegateCommand (PRISM) & ToggleSwitch

1 Answer 124 Views
ToggleSwitch
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dmitry
Top achievements
Rank 1
Dmitry asked on 17 May 2012, 03:24 PM
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)

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 19 May 2012, 09:54 AM
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 >>

Tags
ToggleSwitch
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or