fixed clear MultiFormatTextBox does not work,

implemented com port auto select if none is selected and refreshed
master
Jonas Arnold 3 years ago
parent d8670a37db
commit 236111f94e
  1. 8
      MultiTerm.Core/ViewModel/CommunicationDataViewModel.cs
  2. 5
      MultiTerm.Protocols/Serial/SerialProtocolSettingsViewModel.cs
  3. 9
      MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs
  4. 2
      MultiTerm.Wpf/View/SendReceiveView.xaml
  5. 2
      MultiTerm.Wpf/View/SettingsView/SerialSettingsView.xaml

@ -98,7 +98,11 @@ public partial class CommunicationDataViewModel : ObservableObject
// set new newline separator type and overwrite data collection (triggers property changed)
this.currentReceiveNewlineSeparatorType = (NewlineSeparatorType)receiveNewlineSeparatorType;
// update collection, invoke ui thread if necessary
ContextHelpers.InvokeIfNecessary(this.uiContext, (Action)delegate
{
this.ReceivedData = ReorderDataCollection(this.ReceivedData, this.currentReceiveNewlineSeparatorType);
});
}
if (sendNewlineSeparatorType != null)
{
@ -107,7 +111,11 @@ public partial class CommunicationDataViewModel : ObservableObject
// set new newline separator type and overwrite data collection (triggers property changed)
this.currentSentNewlineSeparatorType = (NewlineSeparatorType)sendNewlineSeparatorType;
// update collection, invoke ui thread if necessary
ContextHelpers.InvokeIfNecessary(this.uiContext, (Action)delegate
{
this.SentData = ReorderDataCollection(this.SentData, this.currentSentNewlineSeparatorType);
});
}
}

@ -35,6 +35,11 @@ public partial class SerialProtocolSettingsViewModel : ProtocolSettingsViewModel
private void ReloadComPorts()
{
this.ComPorts = SerialProtocol.GetPortNames();
// select first COM port, if none is selected yet and there are some available
if (String.IsNullOrEmpty(this.PortName) && this.ComPorts.Any())
{
this.PortName = this.ComPorts.First();
}
}
public SerialProtocolSettingsViewModel(IMessenger messenger) : base(messenger)

@ -105,9 +105,14 @@ public class MultiFormatTextBox : Control
private static void OnCurrentMultiFormatStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// extract instance and guard null
// if (d is not MultiFormatTextBox mftb) { return; }
if (d is not MultiFormatTextBox mftb) { return; }
if (e.NewValue is not MultiFormatString newString) { return; }
// nothing to do
// new value is an empty string => clear
if(newString.FormatValuePairs.Count == 0)
{
mftb.richTextBox!.Document.Blocks.Clear();
}
}

@ -71,7 +71,7 @@
<!-- Send text box -->
<DockPanel DockPanel.Dock="Top" LastChildFill="True">
<Button DockPanel.Dock="Right" Content="Send" Command="{Binding SendCommand}"/>
<custom_controls:MultiFormatTextBox DockPanel.Dock="Left" CurrentMultiFormatString="{Binding Path=SendData, Mode=TwoWay}"></custom_controls:MultiFormatTextBox>
<custom_controls:MultiFormatTextBox DockPanel.Dock="Left" CurrentMultiFormatString="{Binding Path=SendData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></custom_controls:MultiFormatTextBox>
</DockPanel>
<Separator/>
<TextBox DockPanel.Dock="Bottom" Text="{Binding SentData}">

@ -43,7 +43,7 @@
</StackPanel.Resources>
<Label Margin="10 0" VerticalAlignment="Center">Port: </Label>
<ComboBox Width="75" ItemsSource="{Binding Path=ComPorts}" SelectedItem="{Binding Path=PortName}"/>
<ComboBox Width="75" ItemsSource="{Binding Path=ComPorts}" SelectedItem="{Binding Path=PortName, Mode=TwoWay}"/>
<Button Margin="5 0" Content="R" Command="{Binding ReloadComPortsCommand}" Width="25"/>
<Label Margin="20 0 10 0" VerticalAlignment="Center">Baud Rate:</Label>

Loading…
Cancel
Save