Nested properties binding in code

8 posts, 0 answers
  1. tarnegur
    tarnegur avatar
    11 posts
    Member since:
    Jun 2014

    Posted 17 Dec 2014 Link to this post

    Hi.

    I use the property editor and want almost all of the properties to be auto generated, because they are dynamically loaded from available modules. But there are some properties, which should be generated as nested properties, so I define them in code like this:

    01.private PropertyDefinition GetOperationTimePropertyDefinition(List<OperationTime> times)
    02.{
    03.    var definition = new PropertyDefinition();
    04. 
    05.    int order = 1;
    06.    foreach (var operationTime in times)
    07.    {
    08.        var binding = new Binding { Source = operationTime, Path = new PropertyPath("")};
    09.         
    10.        var nestedPropertyDefinition = new PropertyDefinition
    11.                                        {
    12.                                            DisplayName = operationTime.DayOfWeek,
    13.                                            OrderIndex = order++,
    14.                                            Binding = binding,
    15.                                            EditorTemplate = FindResource("OperationTimeEditorTemplate") as DataTemplate
    16.                                        };
    17. 
    18.        definition.NestedProperties.Add(nestedPropertyDefinition);
    19.    }
    20. 
    21.    return definition;
    22.}

    The result you can see on the attached screenshot, the properties are generated correctly, but the binding made in line 8 is not working.
    I am getting this binding exceptions:

    System.Windows.Data Error: 40 : BindingExpression path error: 'WorkStartTillPause' property not found on 'object' ''PropertySetViewModel' (HashCode=37731737)'. BindingExpression:Path=WorkStartTillPause; DataItem='PropertySetViewModel' (HashCode=37731737); target element is 'RadTimePicker' (Name=''); target property is 'SelectedValue' (type 'Nullable`1')


    Can you tell me how to construct the binding to get this work?
  2. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 19 Dec 2014 Link to this post

    Hello,

    Please check this forum thread, where a similar question has already been discussed.

    Regards,
    Yoan
    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. tarnegur
    tarnegur avatar
    11 posts
    Member since:
    Jun 2014

    Posted 19 Dec 2014 in reply to Yoan Link to this post

    Hello.

    Thank you for answer.

    I have already found by reflection the created view model and its dynamic properties and have made the bindings to it.
  5. tarnegur
    tarnegur avatar
    11 posts
    Member since:
    Jun 2014

    Posted 19 Dec 2014 Link to this post

    But to make it work I had to change my model, because this solution does not work for list properties, or I am doing something wrong.

    Because I was generating nested properties from a list property on my view model.

    Can you show me a sample, where it is working? With a view model like this, where you generate the nested properties in code for the BList to have 3 nested properties B with custom editor for C and D:
    class Model
    {
        public string A { get; set; }
        public List<B> BList { get { return new { new B(), new B(), new B() } ; } }
    }
     
    class B
    {
        public string C { get; set; }
        public string D { get; set; }
    }
  6. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 23 Dec 2014 Link to this post

    Hi,

    Indeed, you can try to modify your model. If you are using the provided model, and PropertyGrid's AutoGeneratePropertyDefinitions property is True, then our PropertyGrid will generate a CollectionEditor for the BList list. You can check this help article for a reference. So, you can try to modify the model or create a CollectionEditor in code behind.

    Regards,
    Yoan
    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.

     
  7. tarnegur
    tarnegur avatar
    11 posts
    Member since:
    Jun 2014

    Posted 23 Dec 2014 in reply to Yoan Link to this post

    But I don't want it to be a list editor. I want nested properties.

    Please take a look to an example project I made to show you, how I want it to look like.

    https://www.dropbox.com/s/3kxjyer2mner5fp/PropertyGridNestedProperties.zip?dl=0
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 25 Dec 2014 Link to this post

    Hi,

    You can try preparing your custom hierarchy structure when using RadPropertyGrid's unbound mode. That way you can manually define and bind the nested property definitions as you wish.

    Regards,
    Dimitrina
    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.

     
  9. tarnegur
    tarnegur avatar
    11 posts
    Member since:
    Jun 2014

    Posted 29 Dec 2014 in reply to Dimitrina Link to this post

    It works for single sub-properties like Employee.Department, but not for property lists like Employee.Departments with
    public List<Department> Departments { get; set; }
Back to Top
UI for WPF is Visual Studio 2017 Ready