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

How to set PropertyDefinition binding in code

4 Answers 326 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Dean
Top achievements
Rank 1
Dean asked on 09 Feb 2015, 09:07 PM
I have a list of 'Setting' objects in a ViewModel a RadPropertyGrid is bound to. I use OnLoaded event to populate PropertyDefinitions of the RadPropertyGrid with 'Setting' items from the list by creating a PropertyDefinition for each item. DisplayName and Description for each PropertyDefinition created from a 'Setting' object are set  correctly but I cannot set the Binding to display the actual value to be edited. Here is my code:

  foreach (var setting in vm.Settings)
  {     
      Binding myBinding = new Binding();
      myBinding.Source = setting;
      myBinding.Path = new PropertyPath("SomeProperty");
      var pd = new PropertyDefinition();
      pd.Binding = myBinding;
      pd.DisplayName = setting.Name;
      pd.Description = setting.Description;     
      ServerSettingsPropertyGrid.PropertyDefinitions.Add(pd);
  }

What am I doing wrong and how to properly set PropertyDefinition binding in code?

4 Answers, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 11 Feb 2015, 05:20 PM
Hello Dean,

A possible reason for the mentioned behavior is that you are overriding the inherited data context by explicitly setting the Source property. In order to fix this you can comment-out the myBinding.Source = setting; line in your code.

On a side note when adding / removing a lot of PropertyDefinitions (for example more than 100) at runtime, you should consider invoking the respective SuspendNotifications() and ResumeNotifications() methods and raise notifications only once for all the operations.

Please give the suggested approach a try and let us know how it goes.

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dean
Top achievements
Rank 1
answered on 12 Feb 2015, 12:20 AM
Hello Boris,

Thanks for your reply. Unfortunately, removing the Source property did not help.

Again, Description and Name properties are displayed fine, it's just the Binding property that doesn't get populated but when I place a break point after setting the Binding property I can see that the value is there in the Source property of the binding and in the Path property of the binding (screenshot attached, value is 15):

Any other ideas?

Thanks,

Dean
0
Boris
Telerik team
answered on 13 Feb 2015, 11:10 AM
Hello Dean,

Without a sample project to debug I would be only guessing as to why the mentioned behavior occurs. A probable cause would be that the specified binding is not correct.

In order to provide you with better guidance could you please open a support ticket and send us a small runnable sample project that reproduces the issue? By providing us with such a project we will be able to debug it on our side and inform you of our findings. In addition, if you are not entirely sure how to isolate it, you can check this Isolating a problem in a sample project  blog post for some guidance.

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dean
Top achievements
Rank 1
answered on 13 Feb 2015, 06:35 PM
Thanks Boris,

I'll open a ticket and provide a sample project.

Dean
Tags
PropertyGrid
Asked by
Dean
Top achievements
Rank 1
Answers by
Boris
Telerik team
Dean
Top achievements
Rank 1
Share this question
or