8000 fix: 自定义串口波特率显示出来, close #132 · chenxuuu/llcom@acafe33 · GitHub
[go: up one dir, main page]

Skip to content

Commit acafe33

Browse files
committed
fix: 自定义串口波特率显示出来, close #132
1 parent 884a3a4 commit acafe33

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

llcom/View/MainWindow.xaml.cs

+25-17
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
8383
dataShowFrame.Navigate(new Uri("Pages/DataShowPage.xaml", UriKind.Relative));
8484

8585
//加载初始波特率
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+
}
8795

8896
// 绑定事件监听,用于监听HID设备插拔
8997
(PresentationSource.FromVisual(this) as HwndSource)?.AddHook(WndProc);
@@ -675,40 +683,40 @@ private void ClearLogButton_Click(object sender, RoutedEventArgs e)
675683
Tools.Logger.ClearData();
676684
}
677685

686+
private int lastBaudRateSelectedIndex = -1;
678687
private void BaudRateComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
679688
{
689+
//选的没变
690+
if(lastBaudRateSelectedIndex == baudRateComboBox.SelectedIndex)
691+
return;
692+
680693
if (baudRateComboBox.SelectedItem != null)
681694
{
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)
684697
{
685698
int br = 0;
686699
Tuple<bool, string> ret = Tools.InputDialog.OpenDialog(TryFindResource("ShowBaudRate") as string ?? "?!",
687700
"115200", TryFindResource("OtherRate") as string ?? "?!");
688701
if (!ret.Item1 || !int.TryParse(ret.Item2,out br))//啥都没选
689702
{
690703
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;
698704
}
699705
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+
});
707714
}
708715
else
709716
{
710717
Tools.Global.setting.baudRate =
711718
int.Parse((baudRateComboBox.SelectedItem as ComboBoxItem).Content.ToString());
719+
baudRateComboBox.Items[baudRateComboBox.Items.Count - 1] = TryFindResource("OtherRate") as string ?? "?!";
712720
}
713721
}
714722
}

0 commit comments

Comments
 (0)
0