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

[Solved] Custom ItemTemplateSelector

6 Answers 216 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fredrik
Top achievements
Rank 1
Fredrik asked on 23 May 2011, 12:16 PM
Hi !!

We are currently using components from one of your rivals.
We would like to switch to your controls but one feature is a "must have" for us.
We are having a normal template containing 3 items horizontaly in one row.
Then we are having a selected template containing several items in multiple "vertical rows" for the selected row.

In our current toolkits listbox we are using theirs custom "IDataTemplateSelector" interface that are having a method
as  "public DataTemplate SelectTemplate(object item, DependencyObject container, bool isItemSelected)"
In that method we can easily change the current rows template by returning a template of our choice when the row is selected.
Also the isItemSelected has a bool telling us if the current row is selected or unselected.

Our implementation of the IDataTemplateSelector can we then set as ItemTemplateSelector in the xaml for their listbox component.

This is the only thing keeping us from changing to telerik.

Can this bee done with the DataBoundListBox?

P.s We are using MVVM Light toolkit so no code behind in xaml.cs D.s

Hope you understand my question

Regards

Fredrik

6 Answers, 1 is accepted

Sort by
0
Accepted
Deyan
Telerik team
answered on 23 May 2011, 12:46 PM
Hi Fredrik,

Thanks for your interest in RadControls for Windows Phone 7.

As far as I can understand your scenario, you would like to have a custom template selector which is executed when the Selected state of an item is changed and thus provide different templates for selected/not-selected items?

The RadDataBoundListBox allows you to define a template selector which will be executed for each visual item in the viewport of the control. The template selector provides you with the instance of the visual item for which you will have to define a template. The visual item has a property which defines whether it is selected or not so you can use it to decide which template you will be assigning.

In the current version of the control, however, the template selector will not be executed when the state of an item is selected/deselected. You can easily workaround this by handling the SelectionChanging/SelectionChanged events and calling the instance of the template selector manually for both the deselected and the selected items. This implies a few lines of code in your code-behind file.

Since your scenario is interesting, we may consider upgrading the RadDataBoundListBox control to support this behavior out of the box so you won't need to handle the selection events and manually call the template selector.

We look forward to receiving further details on your scenario so that we make sure that we correctly understand it and make the needed estimations.

Thanks for your time.

Kind regards,
Deyan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Fredrik
Top achievements
Rank 1
answered on 23 May 2011, 12:56 PM
Hello !!!

And thank you for a quick response....
That sounds great for us that you having a similar functionalitity in your great control.

Our main goal (as we have right now in your rivals listbox) is to have one row having different templates showing in the selected / deselected scenario when pressing the same row multiple times.

When the user then moves on to a new row then the old one (if it has the "selected" template showing) will return to its normal template and the new one will get it´s selectedtemplate.

Hope you understands and will be able to implement this.

Regards

Fredrik

P.s Do you have a small example of using your templateselector or is it in the online help? D.s
0
Fredrik
Top achievements
Rank 1
answered on 24 May 2011, 08:21 AM
Hello !!

Now I have coded accordingly to your suggestions with a custom templateselector that are working.
But one thing is missing for me......in my selection_changed event I´m calling my templateselectors
SelectTemplate(object item, DependencyObject container) function.
In item I´m putting my raddataboundlistbox´s addeditem, but how can I get hold of the RadDataBoundListBoxItem that is selected to put in the second parameter "container" ??

Regards

Fredrik
0
Deyan
Telerik team
answered on 25 May 2011, 12:03 PM
Hi Fredrik,

Thanks for writing back and for your question.

In the general implementation of the template selector you would not need to pass the container parameter so you basically can call the SelectTemplate method with null as a container parameter.

Otherwise, you can obtain the visual container of a data item by calling the GetContainerForItem method of the RadDataBoundListBox control. Note that this method will return null in case the data item is not realized as a visual item by the UI virtualization mechanism.

Do not hesitate to get back to me in case you have further questions or need assistance.

All the best,
Deyan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Fredrik
Top achievements
Rank 1
answered on 25 May 2011, 12:25 PM
Hi and thanks for response !!!

That sounds great ....will look into that but for now my hands are full of Mango code to do.
You should bee pleased to hear that we have descided to change to your toolkit from now on.

Hope to see some good progress in your awesome toolkit.

Regards

Fredrik
0
Deyan
Telerik team
answered on 25 May 2011, 03:33 PM
Hi Fredrik,

Thanks for writing back.

I am happy to hear that you have chosen us as your component vendor. We are looking forward to working together.

For now, I will consider this ticket closed.

You can write back anytime you have further questions or need assistance.

Regards,
Deyan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
DataBoundListBox
Asked by
Fredrik
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Fredrik
Top achievements
Rank 1
Share this question
or