Implicit Data Template Selector

10 posts, 1 answers
  1. Ceramist
    Ceramist avatar
    31 posts
    Member since:
    Aug 2008

    Posted 30 May 2011 Link to this post

    Does or Will DataForm support the use of the implicit data template selector in Silverlight 5 Beta?
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 30 May 2011 Link to this post

    Hi Ceramist,

    We are always aiming to benefit form the new features in the platform . However I am not sure what do you mean . Which template in the visual structure of RadDataForm  you need to toggle ?
    I will be glad to know some more details on your  usage scenario.

    Best wishes,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Ceramist
    Ceramist avatar
    31 posts
    Member since:
    Aug 2008

    Posted 30 May 2011 Link to this post

    I was wondering about binding the DataForm to a collection comprising different entities and having the DataForm use a unique Data Template for both readonly and newitem/edit depending upon the current record entity type in the collection.  Silverlight 5 permits defining datatemplates based upon a DataType so I was wondering if DataForm - and I suppose any Telerik Silverlight control - would work in this fashion.
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 31 May 2011 Link to this post

    Hi Ceramist,

    I am not sure we can fully  support that  as currently RadDataForm has quite limited support over heterogenous collections  (when using the ItemsSource property) .

    You can still use the CurrentItem , instead of ItemsSource , passing different object one by one .
    In this case the scenario will be supported ( with some collection specific features disabled - e.g. collection navigation )

    Sincerely ,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Ceramist
    Ceramist avatar
    31 posts
    Member since:
    Aug 2008

    Posted 31 May 2011 Link to this post

    Would the use of the different template selectors in the DataForm permit a successful use of a Heterogeneous collection via ItemSource without having the limit the usefulness of the control through using the CurrentItem property?  I think that having this ability would be important for many applications (such as working with inheritance) and a working example would be quite beneficial.

    Thank you, I appreciate your replys.
  7. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 01 Jun 2011 Link to this post

    Hello Ceramist,

    Your request is absolutely reasonable. I have talked to the team and got some positive reaction.  We are definitely going to take advantage of this and other new features in Silverlight5. Such features will be present somewhere after the official Q3  ( can't give a precise date, as we depend on Microsoft's release schedule here) .

    Your feedback and suggestions are appreciated .  I am updating your Telerik points.

    Greetings,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Paul
    Paul avatar
    29 posts
    Member since:
    May 2011

    Posted 03 Feb 2012 Link to this post

    Any word on this? I'd like to use a DataTemplateSelector on a dataform.
  9. Paul
    Paul avatar
    29 posts
    Member since:
    May 2011

    Posted 03 Feb 2012 Link to this post

    I created a bit of a hack to workaround this issue temporarily, it was easier to inherit from RadDataForm rather than recompile the source code. It's pretty straightforward, I added new public properties for template selectors and handled the CurrentItemChanged event.

    I did not want to add this on the codebehind of the page itself because I am trying to follow MVVM as closely as possible, so I wanted my template selector logic inside the control itself.

    There is a bug in my code because unfortunately I don't have enough control over the base class, there should be more protected and overrideable methods on the RadDataForm. For some reason the UI is never getting notified when I set the ReadOnlyItemTemplate, and I can't force is to refresh because like I said I don't have enough control of base class. However if I set "AutoEdit = True" or toggle Edit Mode manually it starts working, so I'm guessing something in the BeginEdit/EndEdit is refreshing the content presenter.

    Fortunately for my situation I want AutoEdit = true, so this bug has no impact on my scenario. Just be advised in case you use a similar approach to mine that ReadOnly templates will not function properly. And hopefully Telerik adds Template Selectors in next release.

    public class RadDataFormEx : RadDataForm
        {
     
            private DataTemplateSelector m_CurrentReadOnlyItemTemplateSelector;
     
            public DataTemplateSelector CurrentReadOnlyItemTemplateSelector
            {
                get { return m_CurrentReadOnlyItemTemplateSelector; }
                set { m_CurrentReadOnlyItemTemplateSelector = value; }
            }
     
            private DataTemplateSelector m_CurrentEditItemTemplateSelector;
     
            public DataTemplateSelector CurrentEditItemTemplateSelector
            {
                get { return m_CurrentEditItemTemplateSelector; }
                set { m_CurrentEditItemTemplateSelector = value; }
            }
     
            private DataTemplateSelector m_CurrentNewItemTemplateSelector;
     
            public DataTemplateSelector CurrentNewItemTemplateSelector
            {
                get { return m_CurrentNewItemTemplateSelector; }
                set { m_CurrentNewItemTemplateSelector = value; }
            }
     
            public RadDataFormEx()
            {
                this.CurrentItemChanged += RadDataFormEx_CurrentItemChanged;
                 
            }
     
            void RadDataFormEx_CurrentItemChanged(object sender, EventArgs e)
            {
                SelectTemplate();
                
            }
     
            protected void SelectTemplate()
            {
                if (CurrentReadOnlyItemTemplateSelector != null)
                    this.ReadOnlyTemplate = CurrentReadOnlyItemTemplateSelector.SelectTemplate(this.CurrentItem, this);
                else
                    this.ReadOnlyTemplate = null;
     
                if (CurrentNewItemTemplateSelector != null)
                    this.NewItemTemplate = CurrentNewItemTemplateSelector.SelectTemplate(this.CurrentItem, this);
                else
                    this.NewItemTemplate = null;
     
                if (CurrentEditItemTemplateSelector != null)
                    this.EditTemplate = CurrentEditItemTemplateSelector.SelectTemplate(this.CurrentItem, this);
                else
                    this.EditTemplate = null;
     
     
     
            }
     
     
     
     
     
        }


  10. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 19 Mar 2012 Link to this post

    Any word, yet?

    I find myself needing to do something similar, but in my case, I need a view-only form, so I need auto-edit off.
    And, with auto-edit off, the form doesn't display. When I enable the edit button, and toggle manually into edit mode, the form displays, but nothing I've tried has made it display on initial load.

    And there's another complexity.  I need dynamically-loaded templates.  That is, I need to pull the format of the items out of an external text source, I can't include them in code.  So I:

    Stream s = new MemoryStream(ASCIIEncoding.Default.GetBytes(myString));
    DataTemplate template = XamlReader.Load(s) as DataTemplate;
    form.ReadOnlyTemplate = template;

    And this doesn't work, even when I am toggling edit mode manually.

    EDITED:

    OK - Never mind.  Just me making another mistake.
  11. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 22 Mar 2012 Link to this post

    Hello Guys,

    DataTemplateSelector support for RadDataForm will be introduced with Q2 2012.

    Regards,
    Ivan Ivanov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
DevCraft banner