private void RemoveMarker(PhotoCalibrationMarker marker) { marker.MouseDown -= Marker_MouseDown; marker.MouseUp -= Marker_MouseUp; marker.PreviewTouchUp -= Marker_PreviewTouchDown; CommonCanvas.Children.Remove(marker); }
private void Markers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { foreach (var obj in e.NewItems) { PhotoCalibrationMarker marker = (PhotoCalibrationMarker)obj; marker.MouseDown += Marker_MouseDown; marker.MouseUp += Marker_MouseUp; marker.PreviewTouchUp += Marker_PreviewTouchDown; CommonCanvas.Children.Add(marker); Canvas.SetZIndex(marker, 3); } } if (e.OldItems != null) { foreach (var obj in e.OldItems) { PhotoCalibrationMarker marker = (PhotoCalibrationMarker)obj; RemoveMarker(marker); } } }
private void Marker_MouseDown(object sender, MouseButtonEventArgs e) { var marker = (PhotoCalibrationMarker)sender; isMarkerDragging = true; this.currentDraggingMarker = marker; this.markerClickOffset = e.GetPosition(CommonCanvas); this.dragStartLocation = marker.CentreLocation; e.Handled = true; }
/// <summary> /// Binds the View (e.g. IInfoLayerElements that are on the CoodTranformedCanvas) to the /// </summary> /// <param name="up">Upper point of the core sample main axis</param> /// <param name="bottom">Bottom point of the core sample main axis</param> /// <param name="side">Any point that is on the side of the core sampe</param> /// <param name="poly">An annotated polygon, that highlights the core sample</param> /// <param name="vm">View Model that desribes the region</param> private static void BindInfoLayer(PhotoCalibrationMarker up, PhotoCalibrationMarker bottom, PhotoCalibrationMarker side, AnnotatedPolygon poly, CalibratedRegionVM vm) { vm.Up = up.CentreLocation; vm.Bottom = bottom.CentreLocation; vm.Side = side.CentreLocation; var b1 = new Binding(nameof(vm.Up)); b1.Source = vm; b1.Mode = BindingMode.TwoWay; up.SetBinding(PhotoCalibrationMarker.CentreLocationLocationProperty, b1); var b2 = new Binding(nameof(vm.Bottom)); b2.Source = vm; b2.Mode = BindingMode.TwoWay; bottom.SetBinding(PhotoCalibrationMarker.CentreLocationLocationProperty, b2); var b3 = new Binding(nameof(vm.Side)); b3.Source = vm; b3.Mode = BindingMode.TwoWay; side.SetBinding(PhotoCalibrationMarker.CentreLocationLocationProperty, b3); var visConverter = new CollapsedConverter(); var b4 = new Binding(nameof(vm.AreMarkersVisible)); b4.Source = vm; b4.Converter = visConverter; up.SetBinding(UIElement.VisibilityProperty, b4); var b5 = new Binding(nameof(vm.AreMarkersVisible)); b5.Source = vm; b5.Converter = visConverter; bottom.SetBinding(UIElement.VisibilityProperty, b5); var b6 = new Binding(nameof(vm.AreMarkersVisible)); b6.Source = vm; b6.Converter = visConverter; side.SetBinding(UIElement.VisibilityProperty, b6); }
private void PlaceMarker(Point position) { PhotoCalibrationMarker toAdd = null; switch (CurrentState) { case MarkupState.SettingUp: toAdd = new PhotoCalibrationMarker() { CentreLocation = position, MarkerName = "Верх", FillBrush = new SolidColorBrush(new Color() { R = 255, G = 150, B = 150, A = 200 }) }; CurrentState = MarkupState.SettingBottom; break; case MarkupState.SettingBottom: toAdd = new PhotoCalibrationMarker() { CentreLocation = position, MarkerName = "Низ", FillBrush = new SolidColorBrush(new Color() { R = 0, G = 255, B = 255, A = 200 }) }; CurrentState = MarkupState.SettingSide; break; case MarkupState.SettingSide: toAdd = new PhotoCalibrationMarker() { CentreLocation = position, MarkerName = "Сторона", FillBrush = new SolidColorBrush(new Color() { R = 255, G = 255, B = 255, A = 200 }) }; CurrentState = MarkupState.SettingUp; break; } canvasMarkers.Add(toAdd); regionDraft.Add(toAdd); if (regionDraft.Count == 3) { //draft is ready CalibratedRegionVM vm = new CalibratedRegionVM(); vm.Length = double.NaN; vm.Up = regionDraft[0].CentreLocation; vm.Bottom = regionDraft[1].CentreLocation; vm.Side = regionDraft[2].CentreLocation; var newCalRegions = new List <CalibratedRegionVM>(CalibratedRegions); foreach (PhotoCalibrationMarker marker in regionDraft) { canvasMarkers.Remove(marker); } newCalRegions.Add(vm); CalibratedRegions = newCalRegions; vm.AreMarkersVisible = true; FocusedRegion = vm; } else { FocusedRegion = null; HideAllPolygonMarkers(); } }