@@ -83,7 +83,15 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
83
83
dataShowFrame . Navigate ( new Uri ( "Pages/DataShowPage.xaml" , UriKind . Relative ) ) ;
84
84
85
85
//加载初始波特率
86
- baudRateComboBox . Text = Tools . Global . setting . baudRate . ToString ( ) ;
86
+ var br = Tools . Global . setting . baudRate . ToString ( ) ;
87
+ if ( baudRateComboBox . Items . Contains ( br ) )
88
+ baudRateComboBox . Text = Tools . Global . setting . baudRate . ToString ( ) ;
89
+ else
90
+ {
91
+ lastBaudRateSelectedIndex = baudRateComboBox . Items . Count - 1 ; //防止弹窗提示
92
+ baudRateComboBox . Items [ baudRateComboBox . Items . Count - 1 ] = br ;
93
+ baudRateComboBox . Text = br ;
94
+ }
87
95
88
96
// 绑定事件监听,用于监听HID设备插拔
89
97
( PresentationSource . FromVisual ( this ) as HwndSource ) ? . AddHook ( WndProc ) ;
@@ -675,40 +683,40 @@ private void ClearLogButton_Click(object sender, RoutedEventArgs e)
675
683
Tools . Logger . ClearData ( ) ;
676
684
}
677
685
686
+ private int lastBaudRateSelectedIndex = - 1 ;
678
687
private void BaudRateComboBox_SelectionChanged ( object sender , SelectionChangedEventArgs e )
679
688
{
689
+ //选的没变
690
+ if ( lastBaudRateSelectedIndex == baudRateComboBox . SelectedIndex )
691
+ return ;
692
+
680
693
if ( baudRateComboBox . SelectedItem != null )
681
694
{
682
- if ( ( baudRateComboBox . SelectedItem as ComboBoxItem ) . Content . ToString ( ) ==
683
- ( TryFindResource ( "OtherRate" ) as string ?? "?!" ) )
695
+ lastBaudRateSelectedIndex = baudRateComboBox . SelectedIndex ;
696
+ if ( baudRateComboBox . SelectedIndex == baudRateComboBox . Items . Count - 1 )
684
697
{
685
698
int br = 0 ;
686
699
Tuple < bool , string > ret = Tools . InputDialog . OpenDialog ( TryFindResource ( "ShowBaudRate" ) as string ?? "?!" ,
687
700
"115200" , TryFindResource ( "OtherRate" ) as string ?? "?!" ) ;
688
701
if ( ! ret . Item1 || ! int . TryParse ( ret . Item2 , out br ) ) //啥都没选
689
702
{
690
703
Tools . MessageBox . Show ( TryFindResource ( "OtherRateFail" ) as string ?? "?!" ) ;
691
- Task . Run ( ( ) =>
692
- {
693
- this . Dispatcher . Invoke ( new Action ( delegate {
694
- baudRateComboBox . Text = Tools . Global . setting . baudRate . ToString ( ) ;
695
- } ) ) ;
696
- } ) ;
697
- return ;
698
704
}
699
705
Tools . Global . setting . baudRate = br ;
700
- if ( Tools . Global . setting . baudRate != br ) //说明设置失败了
701
- Task . Run ( ( ) =>
702
- {
703
- this . Dispatcher . Invoke ( new Action ( delegate {
704
- baudRateComboBox . Text = Tools . Global . setting . baudRate . ToString ( ) ;
705
- } ) ) ;
706
- } ) ;
706
+ Task . Run ( ( ) =>
707
+ {
708
+ this . Dispatcher . Invoke ( new Action ( delegate {
709
+ var text = Tools . Global . setting . baudRate . ToString ( ) ;
710
+ baudRateComboBox . Items [ baudRateComboBox . Items . Count - 1 ] = text ;
711
+ baudRateComboBox . Text = text ;
712
+ } ) ) ;
713
+ } ) ;
707
714
}
708
715
else
709
716
{
710
717
Tools . Global . setting . baudRate =
711
718
int . Parse ( ( baudRateComboBox . SelectedItem as ComboBoxItem ) . Content . ToString ( ) ) ;
719
+ baudRateComboBox . Items [ baudRateComboBox . Items . Count - 1 ] = TryFindResource ( "OtherRate" ) as string ?? "?!" ;
712
720
}
713
721
}
714
722
}
0 commit comments