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

Caching ICustomTypeProvider

9 Answers 40 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Franz
Top achievements
Rank 1
Franz asked on 15 Jul 2013, 10:20 AM
Hi,

I implement an application, where some objects, which exist on server, are edited remotely in a Silverlight application.

For editing of properties of an object I use the RadPropertyGrid control. Because there is no actual type of the edited object in the Silverlight app, I implemented a class, which implement the ICustomTypeProvider interface, and which returns all necessary metadata.

Everything works fine until I need to edit an object of another type. The RadPropertyGrid always shows property of the first type.

I analyzed your code, and found the following:

internal static IEnumerable<ItemPropertyInfo> RetrieveItemPropertiesFromPropertyDescriptors(object item)

{

       if (item != null && ShouldCacheProertyDescriptorsForType(item.GetType()) && ItemPropertiesCache.ContainsKey(item.GetType().AssemblyQualifiedName))

       {

            return ItemPropertiesCache[item.GetType().AssemblyQualifiedName];

       }

       if (ItemPropertiesCache.ContainsKey(item.GetType().AssemblyQualifiedName))

       {

            return ItemPropertiesCache[item.GetType().AssemblyQualifiedName];

       }

       else

       {

            var result = CreateItemPropertyInfoFromDescriptor(GetPropertyDescriptors(item));

            if (item != null && ShouldCacheProertyDescriptorsForType(item.GetType()))

            {

                 ItemPropertiesCache.Add(item.GetType().AssemblyQualifiedName, result);

            }

            return result;

       }

}

First of all, in the code the to ifs check actually the same. If the first one is false because the item implements IDynamicMetaObjectProvider, anyway the second if is always true.

So, because I have only one class, which implement the ICustomTypeProvider interface, the first set of properties is always cached.

What can I do in this situation? Could you please fix it in you next version?

Sorry, it was a question about PropertyGrid.

 

 

 

 

9 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 17 Jul 2013, 01:57 PM
Hello Franz,

I have tried to reproduce the behavior, but still without much success. Based on the example from this blog post, I prepared a project with RadPropertyGrid that has its Item changed. Could you take a look at it and let me know whether I am missing something ? Can you reproduce the same behavior on it ?  

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Franz
Top achievements
Rank 1
answered on 17 Jul 2013, 03:00 PM
Hello,

Thanks you so much for fast response.

The problem with the sample from the blog post is, that the dynamic types are not 100% dynamic. The Customer and Product classes are defined in the project, and to these classes some additional properties are added.

I need completely dynamic classes. So that the CustomTypeHelper class cannot be generic. There is no classes, with which I can use it.

I modified the sample, so that it creates completely dynamic classes. As you see, if you press first Customer button, than you see properties of it. Everything ok. Now press Product. Still properties of Customer are displayed (with no values).

The problem is with RadPropertyGrid caching properties of a type. But I have only one type: CustomTypeHelper.

Even the sample from the blog would no work with the RadPropertyGrid, if it is needed to some later time point add some additional properties. For example to CustomTypeHelper<Customer> instance.

Here you can get my sample:

http://dl.membrain-it.com/telerik/
0
Maya
Telerik team
answered on 22 Jul 2013, 11:08 AM
Hi Franz,

Indeed, you are right - in this case properties for the second scenario are not created. The thing is that there is no unified method by which we can understand what the implementation of the interface is and how properties are added/ removed. And consequently, there might be a lot of different approaches which we cannot anticipate. That is why we cannot improve the behavior so that out-of-the-box the newly added properties are created. You can observe the same behavior with Microsoft controls as well - for example DataGrid will not generate column for the new properties.
What I can suggest is either to follow the approach from the sample I previously attached or generate PropertyDefinition-s on your own. 

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Franz
Top achievements
Rank 1
answered on 22 Jul 2013, 11:36 AM
Hi Maya,

> or generate PropertyDefinition-s on your own. 

I'm not quite sure what you mean by this. If you mean custom PropertyInfo, then this is already done in both original, as well modified samples.

I see in your code, that you skip caching of Properties of type implementing IDynamicMetaObjectProvider interface:

private static bool ShouldCacheProertyDescriptorsForType(Type type)

{

#if WPF40

return !type.IsCompatibleWith(typeof(ICustomTypeDescriptor)) && !type.IsCompatibleWith(typeof(IDynamicMetaObjectProvider));

#elif SILVERLIGHT

return !type.IsCompatibleWith(typeof(IDynamicMetaObjectProvider));

#endif

}

My suggestion is to add also ICustomTypeProvider for Silveright:

private static bool ShouldCacheProertyDescriptorsForType(Type type)

{

#if WPF40

return !type.IsCompatibleWith(typeof(ICustomTypeDescriptor)) && !type.IsCompatibleWith(typeof(IDynamicMetaObjectProvider));

#elif SILVERLIGHT

return !type.IsCompatibleWith(typeof(IDynamicMetaObjectProvider)) && !type.IsCompatibleWith(typeof(ICustomTypeProvider));

#endif

}

Regards.

 

 

 

 

 

 

0
Maya
Telerik team
answered on 22 Jul 2013, 11:46 AM
Hello Franz,

My suggestion was to create PropertyDefinition of the property grid:

var propertyDefinition = new PropertyDefinition() {Binding = new Binding("MyProperty")};
this.myPropertyGrid.PropertyDefinitions.Add(propertyDefinition);
 

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
ITA
Top achievements
Rank 1
answered on 05 Feb 2014, 11:03 AM
Hi,

do you have the attached example also for wpf?

Thanks
Rene
0
Maya
Telerik team
answered on 07 Feb 2014, 08:37 AM
Hello Rene,

Will it be possible to clarify what kind of example you need ? What functionality do you require for it to demonstrate ? 

Regards,
Maya
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

0
ITA
Top achievements
Rank 1
answered on 07 Feb 2014, 08:54 AM
Hi,

the problem ist, that i have to create Properties on runtime and bind the object to a GridView. I create a Full text search
for our business-software and out of this software i get different databases and tables with different columns and i want
to use one object!

 I found solutins for Silverlight ICustomTypeProvider, but i need an example for wpf (standalone pur wpf no silverlight at all).

Thanks
Best Regardes
0
Maya
Telerik team
answered on 12 Feb 2014, 12:08 PM
Hello Rene,

Once you implement ICustomTypeProvider - it should be similar to the one in this blog post, you can set the Item to the property grid as follows:
public MainWindow()
        {
            InitializeComponent();
 
            Customer.AddProperty("Name", typeof(string));
 
            Customer customer1 = new Customer();
            customer1.SetPropertyValue("Name", "Chris");       
 
            this.customerPropertyGrid.Item = customer1;        
        }

Please keep in mind that ICustomTypeProvider is available only in .Net 4.5



Regards,
Maya
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

Tags
PropertyGrid
Asked by
Franz
Top achievements
Rank 1
Answers by
Maya
Telerik team
Franz
Top achievements
Rank 1
ITA
Top achievements
Rank 1
Share this question
or