private void OnMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { var pos = e.GetPosition(FlexChart); SelectedAnnotation = HitTest(pos); //Dispatcher.BeginInvoke(new Action(() => //{ if (SelectedAnnotation != null && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { _oldPoint = pos; _isDragging = true; //Start Dragging FlexChart.Cursor = Cursors.SizeAll; } else { if (AllowAdd && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { this._start = pos; if (this.NewAnnotationType == typeof(Text)) { AddAnnotation(_start); } } else if (e.RightButton != MouseButtonState.Pressed) { SelectedAnnotation = null; _flexChart.Invalidate(); } } //})); }
//Binding view mode property setting panel public static void BindingSettingsParams(C1FlexChart chart, object source, Type srcType, string srckey, IEnumerable <Data.PropertyParam> properties, Action propertyChangedCallback = null) { IEnumerable <Data.SettingParam> settings; if (ViewModel.ViewModel.Instance.Settings.TryGetValue(srckey, out settings)) { foreach (var param in properties) { var setting = (from p in settings where (param.Group == null) ? p.Key == param.Key : (p.Key == param.Key && p.Group == param.Group) select p).FirstOrDefault(); if (setting != null) { Queue <string> keys = new Queue <string>(param.Key.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)); KeyValuePair <System.Reflection.PropertyInfo, object> propertyInfo = GetPropertyInfo(source, srcType, keys); SetPropertyValue(setting, param, propertyInfo); setting.PropertyChanged += (o, e) => { SetPropertyValue(setting, param, propertyInfo); if (propertyChangedCallback != null) { propertyChangedCallback(); } chart.Invalidate(); }; } } } }
public EditableAnnotationLayer(C1FlexChart chart) { AllowMove = true; _flexChart = chart; Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown; _flexChart.DoubleTapped += _flexChart_DoubleTapped; _flexChart.RightTapped += _flexChart_RighTapped; _flexChart.PointerPressed += _flexChart_PointerPressed; _flexChart.PointerReleased += _flexChart_PointerReleased; _flexChart.PointerMoved += _flexChart_PointerMoved; _flexChart.Rendered += OnChartRendered; Annotations.CollectionChanged += OnCollectionChanged; _rectCache = new List <AnnotationEx>(); _originalStyle = new ChartStyle() { Fill = new SolidColorBrush(Colors.Red) }; SelectionStyle = new ChartStyle() { Fill = new SolidColorBrush(Colors.White), Stroke = new SolidColorBrush(Colors.Red), StrokeThickness = 1, StrokeDashArray = new DoubleCollection() { 1, 2 } }; TextAnnoStyle = new ChartStyle() { FontSize = 12, Stroke = new SolidColorBrush(Colors.Black) }; Attachment = AnnotationAttachment.Absolute; //Popup to show Annotation editor EditorPopup = new Popup(); EditorPopup.IsLightDismissEnabled = true; FlexChart.KeyDown += (s1, e1) => { if (e1.Key == Windows.System.VirtualKey.Escape) { HideContentEditor(); } }; EditorPopup.Closed += (s1, e1) => { _flexChart.Invalidate(); }; }
public EditableAnnotationLayer(C1FlexChart chart) { AllowMove = true; _flexChart = chart; _flexChart.PreviewMouseDown += OnPreviewMouseDown; _flexChart.MouseDown += OnMouseDown; _flexChart.PreviewMouseLeftButtonUp += _flexChart_PreviewMouseLeftButtonUp; _flexChart.MouseUp += OnMouseUp; _flexChart.MouseMove += OnMouseMove; _flexChart.MouseDoubleClick += OnMouseDoubleClick; _flexChart.Rendered += OnChartRendered; Annotations.CollectionChanged += OnCollectionChanged; _rectCache = new List <AnnotationEx>(); _originalStyle = new ChartStyle { Fill = Brushes.Red }; SelectionStyle = new ChartStyle { Fill = Brushes.White, Stroke = Brushes.Red, StrokeThickness = 1, StrokeDashArray = new DoubleCollection() { 1, 2 } }; Attachment = AnnotationAttachment.Absolute; //Popup to show Annotation editor EditorPopup = new Popup(); EditorPopup.AllowsTransparency = true; EditorPopup.Placement = PlacementMode.AbsolutePoint; EditorPopup.PlacementTarget = FlexChart; FlexChart.KeyDown += (s1, e1) => { if (e1.Key == Key.Escape) { HideContentEditor(); } }; EditorPopup.Closed += (s1, e1) => { _flexChart.Invalidate(); }; }
private void _flexChart_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse) { var p = e.GetCurrentPoint((UIElement)sender); if (!p.Properties.IsLeftButtonPressed) { if (HitTest(p.Position) != null) { Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 3); } else { Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 1); } return; } } if (AllowMove && SelectedAnnotation != null && _isDragging && _flexChart.PlotRect.Contains(e.GetCurrentPoint(FlexChart).Position)) { Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1); _newPoint = e.GetCurrentPoint(FlexChart).Position; var diff = new Point { X = _newPoint.X - _oldPoint.X, Y = _newPoint.Y - _oldPoint.Y }; if (SelectedAnnotation is Line) { var line = SelectedAnnotation as Line; var start = Helpers.AnnoPointToCoords(_flexChart, line, line.Start); var end = Helpers.AnnoPointToCoords(_flexChart, line, line.End); start = start.OffSet(diff); end = end.OffSet(diff); line.Start = Helpers.CoordsToAnnoPoint(_flexChart, line, start); line.End = Helpers.CoordsToAnnoPoint(_flexChart, line, end); _flexChart.Invalidate(); } else if (SelectedAnnotation is Polygon) { var polygon = SelectedAnnotation as Polygon; for (int i = 0; i < polygon.Points.Count; i++) { var pt = Helpers.AnnoPointToCoords(_flexChart, polygon, polygon.Points[i]); pt = pt.OffSet(diff); polygon.Points[i] = Helpers.CoordsToAnnoPoint(_flexChart, polygon, pt); } } else { var location = Helpers.AnnoPointToCoords(_flexChart, SelectedAnnotation, SelectedAnnotation.Location); location = location.OffSet(diff); SelectedAnnotation.Location = Helpers.CoordsToAnnoPoint(_flexChart, SelectedAnnotation, location); _flexChart.Invalidate(); } _oldPoint = _newPoint; _flexChart.Invalidate(); return; } if (AllowAdd && _start != null && (FlexChart.HitTest(e.GetCurrentPoint(FlexChart).Position)).ChartElement == ChartElement.PlotArea) { if (_drawing) { UpdateAnnotation(e.GetCurrentPoint(FlexChart).Position); _flexChart.Invalidate(); } else { Size sz = new Size { Height = Math.Abs(_start.Y - (float)e.GetCurrentPoint(FlexChart).Position.Y), Width = Math.Abs(_start.X - (float)e.GetCurrentPoint(FlexChart).Position.X) }; Size threshold = new Size(2, 2); if (sz.Width > (float)threshold.Width && sz.Height > (float)threshold.Height && HitTest(_start) == null) { AddAnnotation(_start, e); _flexChart.Invalidate(); } } } }