SerialPortSetup.xaml.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO.Ports;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. namespace WpfTest1.SmallDialogs.Debug
  16. {
  17. /// <summary>
  18. /// SerialPortSetup.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class SerialPortSetup : Window
  21. {
  22. public string result;
  23. public SerialPortSetup()
  24. {
  25. InitializeComponent();
  26. updateButtonClicked(null, null);
  27. button2.IsEnabled = false;
  28. }
  29. private void updateButtonClicked(object sender, RoutedEventArgs e)
  30. {
  31. button2.IsEnabled = false;
  32. comboBox.Items.Clear();
  33. string[] sps = SerialPort.GetPortNames();
  34. foreach (string s in sps) comboBox.Items.Add(s);
  35. }
  36. private void button2_Click(object sender, RoutedEventArgs e)
  37. {
  38. result = (string)comboBox.SelectedItem;
  39. Close();
  40. }
  41. private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  42. {
  43. button2.IsEnabled = comboBox.SelectedItem != null;
  44. }
  45. }
  46. }