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

Nested properties binding in code

7 Answers 334 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
tarnegur
Top achievements
Rank 1
tarnegur asked on 17 Dec 2014, 01:43 PM
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?

7 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 19 Dec 2014, 03:39 PM
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.

 
0
tarnegur
Top achievements
Rank 1
answered on 19 Dec 2014, 04:55 PM
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.
0
tarnegur
Top achievements
Rank 1
answered on 19 Dec 2014, 05:50 PM
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; }
}
0
Yoan
Telerik team
answered on 23 Dec 2014, 01:19 PM
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.

 
0
tarnegur
Top achievements
Rank 1
answered on 23 Dec 2014, 02:38 PM
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
0
Dimitrina
Telerik team
answered on 25 Dec 2014, 09:32 AM
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.

 
0
tarnegur
Top achievements
Rank 1
answered on 29 Dec 2014, 07:02 AM
It works for single sub-properties like Employee.Department, but not for property lists like Employee.Departments with
public List<Department> Departments { get; set; }
Tags
PropertyGrid
Asked by
tarnegur
Top achievements
Rank 1
Answers by
Yoan
Telerik team
tarnegur
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or