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

Using DataTemplates with VisualizationLayer

6 Answers 147 Views
Map
This is a migrated thread and some comments may be shown as answers.
Jason D
Top achievements
Rank 1
Veteran
Jason D asked on 16 Apr 2018, 08:03 PM

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

Sort by
0
Jason D
Top achievements
Rank 1
Veteran
answered on 17 Apr 2018, 06:58 PM
I have this partly working. If I put all templates into Resources and do not define an ItemTemplate, it does not work. If I put one template into the ItemTemplate and leave the others in Resources, it works. Why?
0
Dinko | Tech Support Engineer
Telerik team
answered on 19 Apr 2018, 12:24 PM
Hello Jason D,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Jason D
Top achievements
Rank 1
Veteran
answered on 25 Apr 2018, 04:19 PM

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.

0
Dinko | Tech Support Engineer
Telerik team
answered on 30 Apr 2018, 02:28 PM
Hi Jason D,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Dinko | Tech Support Engineer
Telerik team
answered on 04 May 2018, 01:54 PM
Hello Jason D,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Jason D
Top achievements
Rank 1
Veteran
answered on 04 May 2018, 02:02 PM
Thanks, Dinko. I have a workaround, so it's not a big issue. Have a good weekend.
Tags
Map
Asked by
Jason D
Top achievements
Rank 1
Veteran
Answers by
Jason D
Top achievements
Rank 1
Veteran
Dinko | Tech Support Engineer
Telerik team
Share this question
or