DataTemplateSelector, containing class of property?

3 posts, 0 answers
  1. Matt
    Matt avatar
    14 posts
    Member since:
    May 2012

    Posted 27 Sep 2012 Link to this post

    When I use a DataTemplateSelector, the type passed into SelectTemplate via the item parameter is PropertyDefinition. I can get things like the name of the property and the type of the property, but how about the type that contains the property? If I have five classes with a string property called "Reference" and I need a data template for each of those, I need the name of the class that contains that property to select the proper template. How do I obtain that information?
  2. Matt
    Matt avatar
    14 posts
    Member since:
    May 2012

    Posted 01 Oct 2012 Link to this post

    Hmm, nobody seems to have an answer to this yet. OK so how about another approach. Perhaps I can solve the problem by creating my own property definitions so I have control over what goes through the template selector. The thing is that my Property Grid isn't being used to edit one type but rather many types depending on what you select in a corresponding tree view. I'm using MVVM and in my view model classes I have a boolean property to indicate whether or not to auto-generate the property defs and then a second property for the property definitions themselves. The PropertyDefinitions property looks like it's read-only though, is there a proper way to databind this to my own collection?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 03 Oct 2012 Link to this post

    Hi,

     Basically a PropertyDefinition depends only on the underlaying property, so that it does not contain any public information about the type which member is that property. You may try storing the DataTemplateSelectorinstance in your ViewModel, so that the Item value is visible in its scope. Apparently, this is not a great MVVM approach. We have discussed this scenario and we have decided to expose the respectivePropertyGridField instance as "Container" parameter in the invocation of of DataTemplateSelector'sSelectTemplate(). As it is a visual element, you would be able to access RadPropertyGrid's Item easily. This change will be available with next week's internal build. As for the PropertyDefinitions property, it is ReadOnly by design. You can try using an attached behavior that subscribes to RadPropertyGrid's loaded event and adding the PropertyDefinitions there. 

    All the best,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top