using GenericWpfApp.ViewModel;
using System;
using System.Collections.Specialized;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace GenericWpfApp.View
{
   /// <summary>
   /// Interaction logic for ImpedanceCheckWindow.xaml
   /// </summary>
   public partial class ImpedanceCheckWindow : Window
   {
      private ImpedanceCheckWindowViewModel _viewModel;

      public ImpedanceCheckWindow()
      {
         InitializeComponent();

         WindowStartupLocation = WindowStartupLocation.CenterOwner;
         Owner = Application.Current.MainWindow;

         btnClose.Visibility = Visibility.Hidden;

         ((INotifyCollectionChanged)lvImpedanceCheck.Items).CollectionChanged += ListView_CollectionChanged;

         _viewModel = new ImpedanceCheckWindowViewModel();
         DataContext = _viewModel;
      }

      protected override void OnContentRendered(EventArgs e)
      {
         base.OnContentRendered(e);

         WinProc.Instance().PerformStto(_viewModel);
      }

      private void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
      {
         DragMove();
      }

      private void btnClose_Click(object sender, RoutedEventArgs e)
      {
         this.Close();
      }

      private void ListView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
      {
         if (e.Action == NotifyCollectionChangedAction.Add)
         {
            // scroll the new item into view   
            lvImpedanceCheck.ScrollIntoView(e.NewItems[0]);
         }
      }
   }
}
