using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using PortfolioManager.ViewModels;
using ScottPlot.Avalonia;

namespace PortfolioManager.Views;

public partial class ScottPlotView : UserControl
{
    private AvaPlot avaPlot = default;
    public ScottPlotView()
    {
        InitializeComponent();
    }

    private void AvaPlot_Loaded(object sender, RoutedEventArgs e)
    {
        // This code will execute when the AvaPlot is loaded
        if (sender is ScottPlot.Avalonia.AvaPlot)
        {
          if (default == avaPlot)
          {
              PlotterWorkspaceViewModel viewModel = (DataContext as PlotterWorkspaceViewModel);
              viewModel.OnPlotterLoaded(this.Find<AvaPlot>("AvaPlot"));
          }                
        }
    }
}