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

Strang NullReference exception

4 Answers 120 Views
Book
This is a migrated thread and some comments may be shown as answers.
stavros sotirchos
Top achievements
Rank 1
stavros sotirchos asked on 02 Feb 2011, 04:43 AM
The scenario is the following:

I use a RadBook inside a Page that loads through the classic Navigation system from silverlight. The RadBook show a number of images as a book that come as entities from a ria service. I have a viewmodel class that holds an ObservableCollection of those image classes (the url of the image and some metadata) and an integer to hold the current page. I have done a declarative binding of those two with ItemsSource and RightPageIndex (mode=TwoWay) respectively. Everything seems to work smoothly the first time. After a navigation to another collection of images the problem starts. The images load ok but when I try to change the RightPageIndex through the binded property I get the following

A first chance exception of type 'System.NullReferenceException' occurred in Telerik.Windows.Controls.Navigation
Exception Object reference not set to an instance of an object., StackTrace:   at Telerik.Windows.Controls.RadBook.OnCurrentSheetIndexChanged(Int32 newValue, Int32 oldValue)
   at Telerik.Windows.Controls.RadBook.set_CurrentSheetIndex(Int32 value)
   at Telerik.Windows.Controls.RadBook.OnRightPageIndexChanged(Int32 rightPageIndex)
   at Telerik.Windows.Controls.RadBook.OnRightPageIndexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(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.SendDataToTarget()
   at System.Windows.Data.BindingExpression.SourcePropertyChanged(PropertyPathListener sender, PropertyPathChangedEventArgs args)
   at System.Windows.PropertyPathListener.RaisePropertyPathStepChanged(PropertyPathStep source)
   at System.Windows.PropertyAccessPathStep.RaisePropertyPathStepChanged(PropertyListener source)
   at System.Windows.CLRPropertyListener.SourcePropertyChanged(Object sender, PropertyChangedEventArgs args)
   at System.Windows.Data.WeakPropertyChangedListener.PropertyChangedCallback(Object sender, PropertyChangedEventArgs args)
   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
   at ePaper.ViewModels.ViewModelBase.OnPropertyChanged(String propertyName)

I must mention that on the delegate called after the load of gallery items from the ria service I Clear the ObservableCollection and initialize the RightPageIndex to -1.

4 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 07 Feb 2011, 12:23 PM
Hi stavros sotirchos,

Thank you for reporting this issue. I added it in our PITS under the name: Book: Setting the RightPageIndex throws exception and you will be able to track its progress from tomorrow the latest. I also updated your Telerik points accordingly.

The exception is throws because the RadBook ItemContainerGenerator's Status is NotStarted when you're trying to change the RightPageIndex. Therefore as a workaround you can set the property controlling the RightPageIndex in a dispatcher:
this.Dispatcher.BeginInvoke(new Action(() => { dataContext.CurrentIndex = 2; }));

Give this approach a try and let us know if it works for you or if you need more info.

Best wishes,
Tina Stancheva
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
stavros sotirchos
Top achievements
Rank 1
answered on 08 Feb 2011, 07:22 PM
I've removed the binding and used code behind to set the RightPageIndex. This solution seems to work although I don't like it 
0
Madan
Top achievements
Rank 1
answered on 04 Sep 2012, 07:02 AM
Hi Team,

I get the nullreference exception when changing the rightpageindex.

 


Exception Object reference not set to an instance of an object., StackTrace:   at Telerik.Windows.Controls.RadBook.OnCurrentSheetIndexChanged(Int32 newValue, Int32 oldValue)
   at Telerik.Windows.Controls.RadBook.set_CurrentSheetIndex(Int32 value)
   at Telerik.Windows.Controls.RadBook.OnRightPageIndexChanged(Int32 rightPageIndex)
   at Telerik.Windows.Controls.RadBook.OnRightPageIndexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)


Telereik version i use is 2011.2.1004.1040.




0
Hristo
Telerik team
answered on 07 Sep 2012, 06:22 AM
Hello Stavros,

You could try setting the desired index after the containers has been generated. You could use the ItemContainerGenerator.StatusChanged event and perform a check whether  ItemContainerGenerator.Status is equal to the status "GontainersGenerated". If that condition is satisfied you should be able to set RightPageIndex without exceptions.

Hope this helps. Please let us know if the suggested solution is not working for your case.

Regards,
Hristo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Book
Asked by
stavros sotirchos
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
stavros sotirchos
Top achievements
Rank 1
Madan
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or