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

Exception when setting DataContext to null

14 Answers 379 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Miłosz Cechnicki
Top achievements
Rank 1
Miłosz Cechnicki asked on 16 Dec 2009, 11:38 AM
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


14 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 18 Dec 2009, 03:17 PM
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.
0
Imran Shafiq
Top achievements
Rank 1
answered on 28 Jun 2010, 10:40 AM
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
0
George
Telerik team
answered on 01 Jul 2010, 01:50 PM
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
0
pompomJuice
Top achievements
Rank 1
answered on 19 Oct 2010, 11:11 AM
Having the same problems.

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

Highly annoying.

(Running latest version)
0
George
Telerik team
answered on 22 Oct 2010, 10:52 AM
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
0
pompomJuice
Top achievements
Rank 1
answered on 26 Oct 2010, 03:52 PM
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.
0
pompomJuice
Top achievements
Rank 1
answered on 27 Oct 2010, 12:50 PM
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".

0
George
Telerik team
answered on 31 Oct 2010, 05:24 PM
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
0
pompomJuice
Top achievements
Rank 1
answered on 01 Nov 2010, 08:28 AM
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.  
0
George
Telerik team
answered on 04 Nov 2010, 09:10 AM
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
0
Henk
Top achievements
Rank 1
answered on 11 Nov 2010, 04:30 PM
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.
0
Valeri Hristov
Telerik team
answered on 11 Nov 2010, 05:02 PM
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
0
Henk
Top achievements
Rank 1
answered on 11 Nov 2010, 05:49 PM
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.
0
Valeri Hristov
Telerik team
answered on 12 Nov 2010, 10:29 AM
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
Tags
ComboBox
Asked by
Miłosz Cechnicki
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Imran Shafiq
Top achievements
Rank 1
George
Telerik team
pompomJuice
Top achievements
Rank 1
Henk
Top achievements
Rank 1
Valeri Hristov
Telerik team
Share this question
or