9 Answers, 1 is accepted
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
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
Thank you, I appreciate your replys.
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
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; } }
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.
DataTemplateSelector support for RadDataForm will be introduced with Q2 2012.
Regards,
Ivan Ivanov
the Telerik team