Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llcom/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<ComboBoxItem Content="1500000" />
<ComboBoxItem Content="2000000" />
<ComboBoxItem Content="3000000" />
<ComboBoxItem Content="{DynamicResource OtherRate}" />
<ComboBoxItem x:Name="baudRateCustomItem" Content="{DynamicResource OtherRate}" PreviewMouseDown="BaudRateCustomItem_PreviewMouseDown" />
</ComboBox>
</StatusBarItem>
<Separator Grid.Column="8" />
Expand Down
32 changes: 26 additions & 6 deletions llcom/View/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
else
{
lastBaudRateSelectedIndex = baudRateComboBox.Items.Count - 1;//防止弹窗提示
baudRateComboBox.Items[baudRateComboBox.Items.Count - 1] = br;
baudRateComboBox.Text = br;
SetBaudRateCustomItemText(br);
baudRateComboBox.Text = GetBaudRateCustomLabel(br);
}

// 绑定事件监听,用于监听HID设备插拔
Expand Down Expand Up @@ -712,12 +712,32 @@ private void ClearLogButton_Click(object sender, RoutedEventArgs e)
}

private int lastBaudRateSelectedIndex = -1;
private bool baudRateCustomItemClicked = false;
private void BaudRateCustomItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
baudRateCustomItemClicked = true;
}
private string GetBaudRateCustomLabel(string value)
{
var baseLabel = TryFindResource("OtherRate") as string ?? "?!";
return string.IsNullOrEmpty(value) ? baseLabel : baseLabel + ":" + value;
}
private void SetBaudRateCustomItemText(string value)
{
string label = GetBaudRateCustomLabel(value);
int last = baudRateComboBox.Items.Count - 1;
var item = baudRateComboBox.Items[last] as ComboBoxItem;
if (item != null) item.Content = label;
else baudRateComboBox.Items[last] = label;
}
private void BaudRateComboBox_Changed(object sender, EventArgs e)
{
//选的没变
if(lastBaudRateSelectedIndex == baudRateComboBox.SelectedIndex)
if(lastBaudRateSelectedIndex == baudRateComboBox.SelectedIndex && !baudRateCustomItemClicked)
return;

baudRateCustomItemClicked = false;

if (baudRateComboBox.SelectedItem != null)
{
lastBaudRateSelectedIndex = baudRateComboBox.SelectedIndex;
Expand All @@ -735,16 +755,16 @@ private void BaudRateComboBox_Changed(object sender, EventArgs e)
{
this.Dispatcher.Invoke(new Action(delegate {
var text = Tools.Global.setting.baudRate.ToString();
baudRateComboBox.Items[baudRateComboBox.Items.Count - 1] = text;
baudRateComboBox.Text = text;
SetBaudRateCustomItemText(text);
baudRateComboBox.Text = GetBaudRateCustomLabel(text);
}));
});
}
else
{
Tools.Global.setting.baudRate =
int.Parse((baudRateComboBox.SelectedItem as ComboBoxItem).Content.ToString());
baudRateComboBox.Items[baudRateComboBox.Items.Count - 1] = TryFindResource("OtherRate") as string ?? "?!";
SetBaudRateCustomItemText("");
}
}
}
Expand Down
Loading