Strang NullReference exception

5 posts, 0 answers
  1. stavros sotirchos
    stavros sotirchos avatar
    16 posts
    Member since:
    Mar 2006

    Posted 01 Feb 2011 Link to this post

    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.
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 07 Feb 2011 Link to this post

    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>>
  3. DevCraft banner
  4. stavros sotirchos
    stavros sotirchos avatar
    16 posts
    Member since:
    Mar 2006

    Posted 08 Feb 2011 Link to this post

    I've removed the binding and used code behind to set the RightPageIndex. This solution seems to work although I don't like it 
  5. Madan
    Madan avatar
    3 posts
    Member since:
    Apr 2012

    Posted 04 Sep 2012 Link to this post

    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.




  6. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 07 Sep 2012 Link to this post

    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.

Back to Top
DevCraft banner