private void SaveBtn_Click(object sender, RoutedEventArgs e) { SerialPortConfig.ServicePort = ServicePortTB.Text; SerialPortConfig.ZigBeeId = ZigBeeIdTB.Text; if (PortNameCB.SelectedIndex != -1) { SerialPortConfig.PortName = PortNameCB.SelectedItem.ToString(); } SerialPortConfig.PortBaudRate = int.Parse(BaudRateTB.Text); SerialPortConfig.PortParity = (Parity)Enum.Parse(typeof(Parity), ParityCB.SelectedItem.ToString(), true); SerialPortConfig.DataBits = int.Parse(DataBitsTB.Text); SerialPortConfig.PortHandshake = (Handshake)Enum.Parse(typeof(Handshake), HandshakeCB.SelectedItem.ToString(), true); SerialPortConfig.PortStopBits = (StopBits)Enum.Parse(typeof(StopBits), StopBitsCB.SelectedItem.ToString(), true); SerialPortConfig.ReadTimeout = int.Parse(ReadTimeoutTB.Text); SerialPortConfig.WriteTimeout = int.Parse(WriteTimeoutTB.Text); SerialPortConfig.Save(); MessageBox.Show("设置成功,服务将自动重启...."); System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); // App.Current.Shutdown(); }