1313using System . Windows . Media ;
1414using CP . WPF . Controls ;
1515using ReactiveUI ;
16- using ReactiveUI . SourceGenerators ;
1716using ScottPlot ;
1817using ScottPlot . Plottables ;
1918
@@ -22,9 +21,8 @@ namespace CrissCross.WPF.Plot;
2221/// <summary>
2322/// Interaction logic for WPF Chart AICS.
2423/// </summary>
25- [ IViewFor < LiveChartViewModel > ]
2624[ SupportedOSPlatform ( "windows10.0.19041" ) ]
27- public partial class LiveChart
25+ public partial class LiveChart : ReactiveUI . ReactiveUserControl < LiveChartViewModel >
2826{
2927 private readonly CompositeDisposable _dd = [ ] ;
3028 private IDisposable ? _crosshairDisposable ;
@@ -37,17 +35,17 @@ public partial class LiveChart
3735 private AxisLine ? _plottableBeingDragged ;
3836
3937 /// <summary>
40- /// Initializes a new instance of the <see cref="LiveChart" /> class.
38+ /// Initializes a new instance of the <see cref="LiveChart"/> class.
4139 /// </summary>
4240 public LiveChart ( )
4341 {
4442 InitializeComponent ( ) ;
4543 First = false ;
46- DataContext = ViewModel = new ( MainChartGrid ) { UseFixedNumberOfPoints = UseFixedNumberOfPoints , NumberPointsPlotted = NumberPointsPlotted } ;
44+ ViewModel = new ( MainChartGrid ) { UseFixedNumberOfPoints = UseFixedNumberOfPoints , NumberPointsPlotted = NumberPointsPlotted } ;
45+ DataContext = ViewModel ;
4746 ViewModel . ThrownExceptions . Subscribe ( ex => Debug . WriteLine ( $ "Exception in LiveChart: { ex . Message } ") ) . DisposeWith ( _dd ) ;
4847 ExecuteLockUnlock ( ) ;
4948 ExecuteManAutoScale ( ) ;
50-
5149 InitializeButtons ( ) ;
5250 this . WhenActivated ( ElementBinding1 ) ;
5351 }
@@ -580,46 +578,29 @@ private void MainChartGrid_MouseUp(object sender, MouseEventArgs e)
580578
581579 private void MainChartGrid_MouseMove ( object sender , MouseEventArgs e )
582580 {
583- ////this rectangle is the area around the mouse in coordinate units
584- // MOUSE EVENT
585581 var position = e . GetPosition ( MainChartGrid ) ;
586-
587- // Obtener el DPI Scaling del Grid actual
588582 var dpiInfo = VisualTreeHelper . GetDpi ( MainChartGrid ) ;
589- var dpiScaleX = dpiInfo . DpiScaleX ;
590- var dpiScaleY = dpiInfo . DpiScaleY ;
591-
592- // Ajustar las coordenadas para que sean precisas
593- var adjustedX = position . X * dpiScaleX ;
594- var adjustedY = position . Y * dpiScaleY ;
595-
596- //// determine where the mouse is and send the coordinates
597- ////Pixel mousePixel = new(adjustedX, adjustedY);
598- ////var mouseLocation = ViewModel.WpfPlot1vm!.Plot.GetCoordinates(mousePixel, ViewModel!.XAxis1, ViewModel.YAxisList[0]);
599- ////var xAxe = mouseLocation.X;
600- ////var yAxe = mouseLocation.Y;
583+ var adjustedX = position . X * dpiInfo . DpiScaleX ;
584+ var adjustedY = position . Y * dpiInfo . DpiScaleY ;
601585 var rect = ViewModel ! . WpfPlot1vm ! . Plot . GetCoordinateRect ( ( float ) adjustedX , ( float ) adjustedY , radius : 5 , ViewModel ! . XAxis1 , ViewModel . YAxisList [ 0 ] ) ;
602-
603586 if ( _plottableBeingDragged is null )
604587 {
605- ////set cursor based on what's beneath the plottable
606588 var lineUnderMouse = ViewModel . GetLineUnderMouse ( ( float ) adjustedX , ( float ) adjustedY ) ;
607589 if ( lineUnderMouse is null )
608590 {
609- Cursor = Cursors . Arrow ;
591+ System . Windows . Input . Mouse . OverrideCursor = System . Windows . Input . Cursors . Arrow ;
610592 }
611593 else if ( lineUnderMouse . IsDraggable && lineUnderMouse is VerticalLine )
612594 {
613- Cursor = Cursors . SizeWE ;
595+ System . Windows . Input . Mouse . OverrideCursor = System . Windows . Input . Cursors . SizeWE ;
614596 }
615597 else if ( lineUnderMouse . IsDraggable && lineUnderMouse is HorizontalLine )
616598 {
617- Cursor = Cursors . SizeNS ;
599+ System . Windows . Input . Mouse . OverrideCursor = System . Windows . Input . Cursors . SizeNS ;
618600 }
619601 }
620602 else
621603 {
622- // update the position of the plottable being dragged
623604 if ( _plottableBeingDragged is HorizontalLine hl )
624605 {
625606 hl . Y = rect . VerticalCenter ;
0 commit comments