MainWindow.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using DeviceCenter.utils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Threading;
  6. using System.Windows;
  7. namespace DeviceCenter
  8. {
  9. /// <summary>
  10. /// MainWindow.xaml 的交互逻辑
  11. /// </summary>
  12. public partial class MainWindow : Window
  13. {
  14. private ObservableCollection<Device> devices = new ObservableCollection<Device>();
  15. public MainWindow()
  16. {
  17. InitializeComponent();
  18. devices.Add(new CarCamDevice() { name = "Device 1", ip = "192.168.1.10", status = Device.Status.CONNECTING });
  19. devices.Add(new AcsDevice() { name = "Device 2", ip = "192.168.1.11", status = Device.Status.FAIL });
  20. devices.Add(new AcsDevice() { name = "Device 3", ip = "192.168.1.12", status = Device.Status.CONNECTED });
  21. lv_device.ItemsSource = devices;
  22. Thread t = new Thread(()=> {
  23. Thread.Sleep(2000);
  24. devices[0].status = Device.Status.CONNECTED;
  25. });
  26. t.Start();
  27. }
  28. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  29. {
  30. //e.Cancel = true;
  31. }
  32. private void btn_add_device_Click(object sender, RoutedEventArgs e)
  33. {
  34. AddDevice addDevice = new AddDevice();
  35. addDevice.ShowDialog();
  36. }
  37. private void btn_del_device_Click(object sender, RoutedEventArgs e)
  38. {
  39. //NotificationUtil.show("连接设备失败", "请检查网络");
  40. if (lv_device.SelectedIndex == -1)
  41. {
  42. return;
  43. }
  44. Console.WriteLine(lv_device.SelectedItem);
  45. MessageBoxResult messageBoxResult = MessageBox.Show("确认删除?", "提示", MessageBoxButton.YesNo);
  46. if (messageBoxResult == MessageBoxResult.Yes)
  47. {
  48. devices.RemoveAt(lv_device.SelectedIndex);
  49. // lv_device.Items.Refresh();
  50. }
  51. }
  52. }
  53. }