I'm adding objects of different types to a virtualization source during the MapItemsRequest call. I'm now trying to format them differently based on their DataType. With a normal control, I can do this:
<
Window.Resources
>
<
DataTemplate
DataType
=
"{x:Type local:Dog}"
>
<
StackPanel
>
<
TextBlock
Text
=
"{Binding Path=Name}"
Background
=
"Green"
/>
</
StackPanel
>
</
DataTemplate
>
<
DataTemplate
DataType
=
"{x:Type local:Cat}"
>
<
StackPanel
>
<
TextBlock
Text
=
"{Binding Path=Name}"
Background
=
"Red"
/>
</
StackPanel
>
</
DataTemplate
>
</
Window.Resources
>
<
Grid
>
<
ListBox
Width
=
"400"
Margin
=
"10"
ItemsSource
=
"{Binding ListItems}"
/>
</
Grid
>
However when using a VisualizationLayer, nothing happens. It seems to be unable to select my templates. Do I have to create template selector in code? I was trying to do everything in XAML.
6 Answers, 1 is accepted
Using the provided code snippet I am wasn't able to fully understand your implementation. Is it possible to elaborate more on your approach? How are you adding the items to the RadMap control?
If you want to apply different templates for your objects on the map you can use ItemTemplateSelector. I have created sample project which demonstrates how you can use ItemTemplateSelector with the RadMap control. The project is attached to this reply.
Regards,
Dinko
Progress Telerik
I attached two samples. Change "gif" to "zip". In DataTemplateTest, items of different types are added to a list. They are displayed differently based on their type because a different data template is defined for each type. I would like to do the same with a map control, without using a template selector.
MapSample is a map version of this technique. I can choose the template based on the DataType, but only if I define an ItemTemplate. For some reason, this sample is attempting to apply this template to all items, even though I have defined the DataType. This gives errors, but displays fine. My real application does not give any error (I don't know why). If I move all templates into the Resources, it does not work.
Thank you for the provided projects.
I am currently investigating this behavior and I need more time. I will contact you again as soon as I have more information about your case.
Regards,
Dinko
Progress Telerik
Thank you for your patience.
After investigation on my side, I can confirm that there is an issue how the templates are applied. That is why I logged it in our Feedback Portal where you can subscribe to the item in order to received notifications for its status changed. I have also updated your Telerik points as a sign of gratitude for pointing this issue to us.
As a workaround, I can only suggest you to try using TemplateSelector or you can consider using the approach mentioned in your last post if it is applicable to your main application.
Regards,
Dinko
Progress Telerik