public MapMarker(MapMarkerContainer markerContainer) : base(MapControl.GetPointLatLong((UIElement)markerContainer.Content)) { Shape = markerContainer; Shape.MouseEnter += (sender, args) => IsMouseOver = true; Shape.MouseLeave += (sender, args) => IsMouseOver = false; Shape.MouseDown += (sender, args) => OnMouseDown(args); UpdateVisibility(); var topDescriptor = DependencyPropertyDescriptor.FromProperty(MapControl.PointLatLongProperty, typeof(FrameworkElement)); topDescriptor.AddValueChanged(markerContainer.Content, (sender, args) => { Position = MapControl.GetPointLatLong(sender as FrameworkElement); UpdateVisibility(); }); }
private MapMarker CreateMarker(object sourceItem) { var template = ItemTemplateSelector != null ? ItemTemplateSelector.SelectTemplate(sourceItem, null) ?? ItemTemplate : ItemTemplate; if (template == null) { return(null); } var dataElement = template.LoadContent() as FrameworkElement; if (dataElement == null) { return(null); } var labelTemplate = _mapControl.ShowLabel ? (LabelTemplateSelector != null ? LabelTemplateSelector.SelectTemplate(sourceItem, null) ?? LabelTemplate : LabelTemplate) : null; var container = new MapMarkerContainer(); container.SetValue(StyleProperty, MarkerContainerStyle); container.Content = dataElement; container.DataContext = sourceItem; if (labelTemplate != null) { container.LabelContent = labelTemplate.LoadContent() as FrameworkElement; } var marker = new MapMarker(container); marker.MouseDown += (sender, args) => SelectMarker((MapMarker)sender, Keyboard.IsKeyDown(Key.LeftShift) || (Keyboard.IsKeyDown(Key.RightShift) || Keyboard.IsKeyDown(Key.LeftCtrl) || (Keyboard.IsKeyDown(Key.RightCtrl)))); return(marker); }