using ProgramLib.GUI.ViewModel;
using System;
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Media.Imaging;

namespace ProgramLib.GUI.View
{
   /// <summary>
   /// Interaction logic for ImpedanceCheckWindow.xaml
   /// </summary>
   internal partial class ImpedanceCheckWindow : Window
   {
      internal ImpedanceCheckWindowViewModel ViewModel { get; set; }

      public ImpedanceCheckWindow()
      {
         InitializeComponent();

         Uri iconUri = new Uri("pack://application:,,,/Program;component/Resources/Icons/app.ico");
         this.Icon = BitmapFrame.Create(iconUri);

         WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

         btnClose.Visibility = Visibility.Hidden;

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

         ViewModel = new ImpedanceCheckWindowViewModel(this);
         DataContext = ViewModel;
      }

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

         // call the delegate to perform STTO
      }

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

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

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