public void RemovePinFromMap(Monument monument) { MonumentPosition mp = Positions.SingleOrDefault(x => x.Monument.Id == monument.Id); if (mp != null) { Positions.Remove(mp); saveMapData(); } }
private void ListView_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("myFormat")) { var a = e.GetPosition((IInputElement)sender); Monument monument = e.Data.GetData("myFormat") as Monument; bool positionConflict = true; int i = 0; while (positionConflict) { i++; positionConflict = false; foreach (MonumentPosition position in Positions) { if (position.Monument.Id != monument.Id) { double diffX = position.Top - (a.X - PinContainerWidth); double diffY = position.Left - (a.Y - PinContainerHeight); if (Math.Sqrt(Math.Pow(diffX, 2) + Math.Pow(diffY, 2)) < 0.1) { a.X -= Math.Sign(diffX) * 0.1 * i; a.Y -= Math.Sign(diffY) * 0.1 * i; } } } } foreach (MonumentPosition position in Positions) { if (position.Monument != null && position.Monument.Id == monument.Id) { position.Left = (a.Y - PinContainerWidth); position.Top = (a.X - PinContainerHeight); UpdateLayout(); updateSelection(); return; } } MonumentPosition mp = new MonumentPosition(a.X - PinContainerHeight, a.Y - PinContainerWidth, monument); var tmp = new List <MonumentPosition>(Positions); tmp.Add(mp); Positions = new ObservableCollection <MonumentPosition>(tmp); UpdateLayout(); updateSelection(); saveMapData(); } }