How to set PropertyDefinition binding in code

5 posts, 0 answers
  1. Dean K.
    Dean K. avatar
    55 posts
    Member since:
    Aug 2011

    Posted 09 Feb 2015 Link to this post

    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?
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 11 Feb 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dean K.
    Dean K. avatar
    55 posts
    Member since:
    Aug 2011

    Posted 11 Feb 2015 in reply to Boris Link to this post

    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
  5. Boris
    Admin
    Boris avatar
    276 posts

    Posted 13 Feb 2015 Link to this post

    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.

     
  6. Dean K.
    Dean K. avatar
    55 posts
    Member since:
    Aug 2011

    Posted 13 Feb 2015 in reply to Boris Link to this post

    Thanks Boris,

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

    Dean
Back to Top
UI for WPF is Visual Studio 2017 Ready