This project has moved. For the latest updates, please go here.

Route markers

Jun 18, 2015 at 1:47 PM
Edited Jun 24, 2015 at 12:05 PM
Greetings! I'm trying to implement custom routes that will have selectable and movable points (the sample map point) and polylines connecting them. I have a class Route and a custom user control for it that spawns both the polylines and the points from the route class that I send to it. Problem is that i can't get it to actually fetch the data and render the points and polylines.
My Route.cs class
``` public class RoutePoint : PropertyChangedBase
{
    private Location location;
    public Location Location
    {
        get { return location; }
        set
        {
            location = value;
            NotifyOfPropertyChange(() => location);
        }
    }
}

public class Route : PropertyChangedBase
{
    public ObservableCollection<RoutePoint> Points { get; set; }
    public BindableCollection<Location> Locations{ get; set; }
    public bool Visible { get; set; }
    public Route()
    {
        Locations = new BindableCollection<Location>();
        Points = new ObservableCollection<RoutePoint>();
        Visible = true;
    }
}
'''

My RouteControl.xaml

<UserControl x:Class="Map_Test.RouteControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:map="clr-namespace:MapControl;assembly=MapControl.WPF"
         mc:Ignorable="d">
<UserControl.Resources>
<DataTemplate x:Key="PolylineItemTemplate">
    <map:MapPolyline Locations="{Binding Locations}" Stroke="Red" StrokeThickness="3"/>
</DataTemplate>
<Style x:Key="PolylineItemStyle" TargetType="map:MapItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="map:MapItem">
                <map:MapPolyline Locations="{Binding Locations}" Stroke="Red" StrokeThickness="3"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

    <Style x:Key="PointItemStyle" TargetType="map:MapItem" >
        <Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>

    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="map:MapItem">
                <Canvas>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="Disabled"/>
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="labelBackground" Storyboard.TargetProperty="Opacity" To="0.7" Duration="0:0:0.1"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualState x:Name="Unselected"/>
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.7" Duration="0:0:0.1"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Path x:Name="selectedPath" Fill="White" Opacity="0">
                        <Path.Data>
                            <EllipseGeometry RadiusX="15" RadiusY="15"/>
                        </Path.Data>
                    </Path>
                    <Path StrokeThickness="2" Fill="Transparent">
                        <Path.Stroke>
                            <SolidColorBrush Color="Gray"/>
                        </Path.Stroke>
                        <Path.Data>
                            <EllipseGeometry RadiusX="8" RadiusY="8"/>
                        </Path.Data>
                    </Path>
                    <Grid Canvas.Left="15" Canvas.Top="-8">
                        <Rectangle x:Name="labelBackground" Fill="White" Opacity="0"/>
                        <!--local:OutlinedText Margin="1" OutlineThickness="1.5" Text="{Binding Name}"/-->
                    </Grid>
                </Canvas>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Panel.ZIndex" Value="1"/>
        </Trigger>
    </Style.Triggers>
</Style>
</UserControl.Resources>
<WrapPanel>
<map:MapItemsControl ItemsSource="{Binding Points}"
                             ItemContainerStyle="{StaticResource PointItemStyle}"
                             IsSynchronizedWithCurrentItem="True"
                             SelectionMode="Extended"/>

<map:MapItemsControl ItemsSource="{Binding Locations}"
                     ItemContainerStyle="{StaticResource PolylineItemStyle}"/>
</WrapPanel>
</UserControl>