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

Implicit Data Template Selector

9 Answers 205 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ceramist
Top achievements
Rank 1
Ceramist asked on 30 May 2011, 08:53 AM
Does or Will DataForm support the use of the implicit data template selector in Silverlight 5 Beta?

9 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 30 May 2011, 09:17 AM
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
0
Ceramist
Top achievements
Rank 1
answered on 30 May 2011, 04:18 PM
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.
0
Pavel Pavlov
Telerik team
answered on 31 May 2011, 09:35 AM
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
0
Ceramist
Top achievements
Rank 1
answered on 31 May 2011, 10:17 PM
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.
0
Accepted
Pavel Pavlov
Telerik team
answered on 01 Jun 2011, 02:56 PM
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
0
Paul
Top achievements
Rank 1
answered on 03 Feb 2012, 06:39 PM
Any word on this? I'd like to use a DataTemplateSelector on a dataform.
0
Paul
Top achievements
Rank 1
answered on 03 Feb 2012, 10:58 PM

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;
 
 
 
        }
 
 
 
 
 
    }


0
Jeff
Top achievements
Rank 1
answered on 19 Mar 2012, 05:05 PM
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.
0
Ivan Ivanov
Telerik team
answered on 22 Mar 2012, 03:31 PM
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 >>
Tags
DataForm
Asked by
Ceramist
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Ceramist
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Share this question
or