Using DataTemplates with VisualizationLayer

7 posts, 0 answers
  1. Jason D
    Jason D avatar
    114 posts
    Member since:
    Jan 2011

    Posted 16 Apr 2018 Link to this post

    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.

  2. Jason D
    Jason D avatar
    114 posts
    Member since:
    Jan 2011

    Posted 17 Apr 2018 Link to this post

    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?
  3. Dinko
    Admin
    Dinko avatar
    899 posts

    Posted 19 Apr 2018 Link to this post

    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.
  4. Jason D
    Jason D avatar
    114 posts
    Member since:
    Jan 2011

    Posted 25 Apr 2018 in reply to Dinko Link to this post

    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.

  5. Dinko
    Admin
    Dinko avatar
    899 posts

    Posted 30 Apr 2018 Link to this post

    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.
  6. Dinko
    Admin
    Dinko avatar
    899 posts

    Posted 04 May 2018 Link to this post

    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.
  7. Jason D
    Jason D avatar
    114 posts
    Member since:
    Jan 2011

    Posted 04 May 2018 in reply to Dinko Link to this post

    Thanks, Dinko. I have a workaround, so it's not a big issue. Have a good weekend.
Back to Top