MapCustomElementSettings.Template Property
Gets or sets the template used to display custom elements generated with these settings.
Namespace: DevExpress.Xpf.Map
Assembly: DevExpress.Xpf.Map.v18.2.dll
Declaration
Property Value
Type | Description |
---|---|
ControlTemplate | A ControlTemplate object. |
Example
This example demonstrates how to customize the appearance and behavior of automatically generated custom map elements. The MapCustomElementSettings class allows specifying parameters of the adapter generated map custom elements.
To do this, assign a MapCustomElementSettings object to the ListSourceDataAdapter.ItemSettings property, and customize one or several of the following properties.
MapCustomElementSettings.Template
- allows specifying the appearance and behavior of custom generated elements.- MapCustomElementSettings.ContentTemplate - allows specifying the appearance of data displayed in custom elements.
- MapCustomElementSettings.ContentTemplateSelector - allows specifying the selector that chooses a template based on data properties.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-customize-the-appearance-and-behavior-of-automatically-generated-map-custom-elements-t213439.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map" x:Class="MapCustomElementSettings.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<XmlDataProvider x:Key="data" Source="Data/Ships.xml" XPath="/Ships"/>
<ControlTemplate x:Key="template">
<Border Name="border" BorderThickness="2" Padding="4"
BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"
Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
<ContentControl Content="{Binding MapItem.Content}"
ContentTemplate="{Binding MapItem.ContentTemplate}"/>
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="BorderBrush.Color"
Storyboard.TargetName="border"
To="{x:Static SystemColors.HotTrackColor}"
Duration="0:0:0"/>
<ColorAnimation Storyboard.TargetProperty="Background.Color"
Storyboard.TargetName="border"
To="{x:Static SystemColors.HighlightColor}"
Duration="0:0:0"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="BorderBrush.Color"
Storyboard.TargetName="border"
To="{x:Static SystemColors.ControlDarkDarkColor}"
Duration="0:0:0"/>
<ColorAnimation Storyboard.TargetProperty="Background.Color"
Storyboard.TargetName="border"
To="{x:Static SystemColors.ControlLightColor}"
Duration="0:0:0"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<DataTemplate x:Key="contentTemplate">
<StackPanel Orientation="Horizontal">
<Image Width="32" Height="32" Source="Images/Ship.png"/>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Year}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<dxm:MapControl CenterPoint="-37, 147" ZoomLevel="5">
<dxm:ImageTilesLayer>
<dxm:BingMapDataProvider BingKey="Your Bing Key"/>
</dxm:ImageTilesLayer>
<dxm:VectorLayer>
<dxm:ListSourceDataAdapter DataSource="{Binding Source={StaticResource data}, XPath=Ship}">
<dxm:ListSourceDataAdapter.Mappings>
<dxm:MapItemMappingInfo Latitude="Latitude" Longitude="Longitude"/>
</dxm:ListSourceDataAdapter.Mappings>
<dxm:ListSourceDataAdapter.ItemSettings>
<dxm:MapCustomElementSettings Template="{StaticResource template}"
ContentTemplate="{StaticResource contentTemplate}"/>
</dxm:ListSourceDataAdapter.ItemSettings>
</dxm:ListSourceDataAdapter>
</dxm:VectorLayer>
</dxm:MapControl>
</Grid>
</Window>
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Template property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.