Exception when setting DataContext to null

15 posts, 0 answers
  1. Miłosz Cechnicki
    Miłosz Cechnicki avatar
    34 posts
    Member since:
    Sep 2009

    Posted 16 Dec 2009 Link to this post

    Hi,
    I get the following exception: "{System.ArgumentNullException: Value cannot be null.
    Parameter name: Text"  when setting the DataContext to null on a control, that contains some RadComboBoxes.

    The stack trace:
       at System.Windows.Controls.TextBox.set_Text(String value)
       at Telerik.Windows.Controls.RadComboBox.TextUpdated(String newText, Boolean textBoxUpdated)
       at Telerik.Windows.Controls.RadComboBox.OnTextChanged(String oldValue, String newValue)
       at Telerik.Windows.Controls.RadComboBox.OnTextChanged(DependencyObject sender, 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()

    I use a dataBinding to the Text property of the RadCombo:
    Text="{Binding ParStyle, Converter={StaticResource StyleSelectionConverter}, Mode=TwoWay}"<br

    Best regards


  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 18 Dec 2009 Link to this post

    Hello Miłosz,

    Thank you for your question.

    We couldn't reproduce the error that you are getting. Attached I am sending you a sample project which I hope is pretty much what you are doing, illustrated in a simple way. If you are still facing difficulties please open a support ticket and send us a running project, which we can test locally.
    Looking forward to your reply.

    Best wishes,
    Konstantina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Imran Shafiq
    Imran Shafiq avatar
    4 posts
    Member since:
    Feb 2010

    Posted 28 Jun 2010 Link to this post

    Hello i am getting exactly the same error with RadComboBox,
                  Ive updated my silverlight 3 business App to Silverlight 4.  My RadComboBox is on a DataForm. When i press cancel, my command Rejects any changes to the WCF RIA Entity bound to the data form. As a result on the RejectChanges statement i get the exact error mentioned above. value cannot be null: parameter named text. The stack trace is also the same.

    Please put the RadCombo Box on a dataform, bind its text property to a string value ( i also have a nulltoemptystringconverter which does not fire when calling reject changes but works fine otherwise )  and then make a sample to reproduce.


    Regards.

    Imran
  5. George
    Admin
    George avatar
    1332 posts

    Posted 01 Jul 2010 Link to this post

    Hi Imran Shafiq,

    Thank you for contacting us.

    We tried to reproduce the problem, but we failed. Could you please send us a sample running project that illustrates the problem ? That should be very helpful to investigate the problem on our side. 

    I will be glad to assist you further.

    Regards,
    George
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. pompomJuice
    pompomJuice avatar
    16 posts
    Member since:
    May 2010

    Posted 19 Oct 2010 Link to this post

    Having the same problems.

    RadCombobox.TextProperty refuses to be bound to an empty or null string.

    Highly annoying.

    (Running latest version)
  7. George
    Admin
    George avatar
    1332 posts

    Posted 22 Oct 2010 Link to this post

    Hi Werner,

    In order to bind Text property of the RadComboBox to a empty or null string, please make sure the RadComboBox is editable and you haven't set EmptyText property. If you set EmptyText property, its value will be applied, instead of empty string. 

    I hope this helps.

    Greetings,
    George
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. pompomJuice
    pompomJuice avatar
    16 posts
    Member since:
    May 2010

    Posted 26 Oct 2010 Link to this post

    Thanks.

    I did what you said but it is still throwing exceptions.

    I also cannot produce a sample project because these problems don't occur in sample projects. The error is random and generally incomprehensible. When I create little text cases like these:

    RadComboBox b = new RadComboBox();
    Binding binding = new Binding("emptytext");
    binding.Source = this;
    binding.Mode = BindingMode.TwoWay;
    emptytext = null;
    b.SetBinding(RadComboBox.TextProperty, binding);

    ...nothing seems to fail yet in my application I get this exception:

    Message =  Value cannot be null. Parameter name: Text (and my binding source its not null its empty string or "")
    StackTrace = 
      
       at System.Windows.Controls.TextBox.set_Text(String value)
       at Telerik.Windows.Controls.RadComboBox.TextUpdated(String newText, Boolean textBoxUpdated)
       at Telerik.Windows.Controls.RadComboBox.OnTextChanged(String oldValue, String newValue)
       at Telerik.Windows.Controls.RadComboBox.OnTextChanged(DependencyObject sender, 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.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
       at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
       at System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, Binding binding)
       at Core.ViewModels.DataFormViewModel.<>c__DisplayClass4.<SetBindings>b__1(KeyValuePair`2 tb)
       at System.Collections.Generic.List`1.ForEach(Action`1 action)
       at Core.ViewModels.DataFormViewModel.SetBindings(FrameworkElement sender)

    Highly annoying problem that I cannot seem to figure out.
  9. pompomJuice
    pompomJuice avatar
    16 posts
    Member since:
    May 2010

    Posted 27 Oct 2010 Link to this post

    Latest findings suggest that for some bizarre reason when you setup bindings in code behind and the Source ever becomes "null" you get these errors instead of the more accustomed silent binding "failure".

  10. George
    Admin
    George avatar
    1332 posts

    Posted 31 Oct 2010 Link to this post

    Hello Werner,

    This issue obviously happens on some rare circumstances. We are really shooting in the dark here. All our attempts to reproduce the problem failed. We will greatly appreciate a project of yours that reproduces the problem. 


    Kind regards,
    George
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. pompomJuice
    pompomJuice avatar
    16 posts
    Member since:
    May 2010

    Posted 01 Nov 2010 Link to this post

    Looking at the other posts combined with how I solved this problem I think it has something to do with meddling with the Text and SelectedItem properties at the same time.

    More documentation is needed on how RadComboBoxes "redo" their bindings when the binding's datacontext changes. The "cross" talk between SelectedItemProperty and TextProperty is caused by some sort of "non atomic" update of the bindings. 

    For example: If I set us up the bindings in the following order: ItemsSource, then SelectedItem and then TextProperty all works fine. If however I switch the order to ItemsSource, TextProperty and then SelectedItem I get all kinds of funny behavior including null exceptions and "cross" talk between entities. This behavior would not be strange if we can get some more documentation on it. How does the combobox update its bindings? Because if it went through it sequentially you can see all kinds of issues cropping up. In my case, when it gets to update the SelectedItemProperty from a new entity datacontext, the TextProperty feeds this update to the old entity because the two properties are connected. 

    So no big worries, but it can get confusing sometimes.  
  12. George
    Admin
    George avatar
    1332 posts

    Posted 04 Nov 2010 Link to this post

    Hi Werner,

    Thank you for your feedback, it helps us in improving our products. We will update our documentation about binding the RadComboBox according your suggestions.

    Please do not hesitate to contact us if you require any further information.

    Greetings,
    George
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. Henk
    Henk avatar
    113 posts
    Member since:
    Apr 2006

    Posted 11 Nov 2010 Link to this post

    Hi,

    I receive the same error in my project.
    I have posted a small sample project as support ticket to reproduce the problem.
    In this small application it is always reproducable.

    Kind Regards.
  14. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 11 Nov 2010 Link to this post

    Hello Henk,

    Thank you for the sample application, it helped a lot. The quick workaround for the problem is to set FallbackValue='':

    <telerik:RadComboBox Name="radComboBox1" DisplayMemberPath="FName" IsEditable="True" Text="{Binding FName, FallbackValue='', Mode=TwoWay}" >

    The code above seems to fix the problem. I will log this issue for resolution, most probably the next week's internal build will contain the fix.

    I apologize for the caused inconvenience.

    Best wishes,
    Valeri Hristov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  15. Henk
    Henk avatar
    113 posts
    Member since:
    Apr 2006

    Posted 11 Nov 2010 Link to this post

    Hi,

    Thanks for the quick answer.
    But I still receive an error when I rebind like this:
    LayoutRoot.DataContext = null;
    boundPerson = null;
      
    ...
      
    boundPerson = new BoundPerson();
    LayoutRoot.DataContext = boundPerson;

    On the last code row I receive the same error.

    Kind Regards.
  16. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 12 Nov 2010 Link to this post

    Hi Henk,

    I don't have a workaround for this problem. Fortunately the change that I made yesterday in RadComboBox seems to fix this problem too, so today's internal build should fix both of them.

    Kind regards,
    Valeri Hristov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft banner