Skip to content

Commit d4bc0aa

Browse files
committed
Fix address selection not updating bindings
1 parent 2110083 commit d4bc0aa

File tree

6 files changed

+44
-16
lines changed

6 files changed

+44
-16
lines changed

src/Core/ViewModels/Pages/ConnectViewModel.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void DeviceManagementServiceOnNakReplyReceived(object? sender, string na
7777

7878
[ObservableProperty] private int _selectedBaudRate = 9600;
7979

80-
[ObservableProperty] private byte _selectedAddress;
80+
[ObservableProperty] private double _selectedAddress;
8181

8282
[ObservableProperty] private byte _connectedAddress;
8383

@@ -249,9 +249,9 @@ await _dialogService.ShowMessageDialog("Connect", $"Invalid security key entered
249249

250250
await _deviceManagementService.Shutdown();
251251
await _deviceManagementService.Connect(
252-
serialPortConnectionService.GetConnection(serialPortName, SelectedBaudRate), SelectedAddress,
252+
serialPortConnectionService.GetConnection(serialPortName, SelectedBaudRate), (byte)SelectedAddress,
253253
UseSecureChannel, UseDefaultKey, securityKey);
254-
ConnectedAddress = SelectedAddress;
254+
ConnectedAddress = (byte)SelectedAddress;
255255
ConnectedBaudRate = SelectedBaudRate;
256256
}
257257
}

src/UI/Windows/Views/Controls/SetCommunicationControl.xaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
<ComboBox Name="BaudRateComboBox"
2121
Margin="0 0 20 0"
2222
ItemsSource="{Binding AvailableBaudRates}"
23-
SelectedItem="{Binding SelectedBaudRate}"/>
23+
SelectedItem="{Binding SelectedBaudRate, Mode=TwoWay}"/>
2424
</StackPanel>
2525
<StackPanel Grid.Column="1" Orientation="Vertical">
2626
<Label Content="Address"
2727
Target="{Binding ElementName=BaudRateComboBox}" />
2828
<ui:NumberBox Name="AddressNumberBox"
29-
Value="{Binding SelectedAddress}"
29+
TextChanged="AddressNumberBox_OnTextChanged"
30+
ValueChanged="AddressNumberBox_OnValueChanged"
31+
Value="{Binding SelectedAddress, Mode=TwoWay}"
3032
Margin="0 0 20 0"
3133
Minimum="0"
3234
Maximum="127"

src/UI/Windows/Views/Controls/SetCommunicationControl.xaml.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.ComponentModel;
22
using System.Runtime.CompilerServices;
3+
using System.Windows.Controls;
4+
using Wpf.Ui.Controls;
35

46
namespace OSDPBench.Windows.Views.Controls;
57

@@ -10,8 +12,8 @@ public SetCommunicationControl(int[] availableBaudRates, uint connectedBaudRate,
1012
DataContext = this;
1113

1214
AvailableBaudRates = availableBaudRates;
13-
_selectedBaudRate = (int)connectedBaudRate;
14-
_selectedAddress = connectedAddress;
15+
SelectedBaudRate = (int)connectedBaudRate;
16+
SelectedAddress = connectedAddress;
1517

1618
InitializeComponent();
1719
}
@@ -25,8 +27,8 @@ public int SelectedBaudRate
2527
set => SetField(ref _selectedBaudRate, value);
2628
}
2729

28-
private byte _selectedAddress;
29-
public byte SelectedAddress
30+
private double _selectedAddress;
31+
public double SelectedAddress
3032
{
3133
get => _selectedAddress;
3234
set => SetField(ref _selectedAddress, value);
@@ -45,4 +47,14 @@ private void SetField<T>(ref T field, T value, [CallerMemberName] string? proper
4547
field = value;
4648
OnPropertyChanged(propertyName);
4749
}
50+
51+
private void AddressNumberBox_OnTextChanged(object sender, TextChangedEventArgs e)
52+
{
53+
SelectedAddress = AddressNumberBox.Value ?? 0;
54+
}
55+
56+
private void AddressNumberBox_OnValueChanged(object sender, NumberBoxValueChangedEventArgs args)
57+
{
58+
SelectedAddress = AddressNumberBox.Value ?? 0;
59+
}
4860
}

src/UI/Windows/Views/Pages/ConnectPage.xaml

+7-5
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,15 @@
152152
<ComboBox Name="BaudRateComboBox"
153153
Margin="0 0 20 0"
154154
ItemsSource="{Binding ViewModel.AvailableBaudRates}"
155-
SelectedItem="{Binding ViewModel.SelectedBaudRate}"/>
155+
SelectedItem="{Binding Path=ViewModel.SelectedBaudRate, Mode=TwoWay}"/>
156156
</StackPanel>
157157
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical">
158158
<Label Content="Address"
159159
Target="{Binding ElementName=AddressNumberBox}" />
160160
<ui:NumberBox Name="AddressNumberBox"
161-
Value="{Binding ViewModel.SelectedAddress}"
161+
Value="{Binding Path=ViewModel.SelectedAddress, Mode=TwoWay}"
162+
TextChanged="AddressNumberBox_OnTextChanged"
163+
ValueChanged="AddressNumberBox_OnValueChanged"
162164
Margin="0 0 20 0"
163165
Minimum="0"
164166
Maximum="127"
@@ -171,19 +173,19 @@
171173
<StackPanel Orientation="Horizontal">
172174
<CheckBox Name="UseSecureChannelCheckBox"
173175
Content="Use Secure Channel"
174-
IsChecked="{Binding ViewModel.UseSecureChannel}"/>
176+
IsChecked="{Binding Path=ViewModel.UseSecureChannel, Mode=TwoWay}"/>
175177

176178
<CheckBox Name="UseDefaultKeyCheckBox"
177179
Content="Use Default Key"
178180
Margin="10,0,0,0"
179181
IsEnabled="{Binding ElementName=UseSecureChannelCheckBox, Path=IsChecked}"
180-
IsChecked="{Binding ViewModel.UseDefaultKey}"/>
182+
IsChecked="{Binding Path=ViewModel.UseDefaultKey, Mode=TwoWay}"/>
181183
</StackPanel>
182184

183185
<StackPanel Orientation="Vertical">
184186
<Label Content="Security Key"
185187
Target="{Binding ElementName=AddressNumberBox}" />
186-
<TextBox Text="{Binding ViewModel.SecurityKey}">
188+
<TextBox Text="{Binding Path=ViewModel.SecurityKey, Mode=TwoWay}">
187189
<TextBox.Style>
188190
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
189191
<!-- Only add the specific triggers needed -->

src/UI/Windows/Views/Pages/ConnectPage.xaml.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using OSDPBench.Core.ViewModels.Pages;
1+
using System.Windows.Controls;
2+
using OSDPBench.Core.ViewModels.Pages;
23
using Wpf.Ui.Abstractions.Controls;
4+
using Wpf.Ui.Controls;
35

46
namespace OSDPBench.Windows.Views.Pages;
57

@@ -27,4 +29,14 @@ public ConnectPage(ConnectViewModel viewModel)
2729
public ConnectViewModel ViewModel { get; }
2830

2931
public IEnumerable<string> ConnectionTypes => ["Discover", "Manual"];
32+
33+
private void AddressNumberBox_OnTextChanged(object sender, TextChangedEventArgs e)
34+
{
35+
ViewModel.SelectedAddress = AddressNumberBox.Value ?? 0;
36+
}
37+
38+
private void AddressNumberBox_OnValueChanged(object sender, NumberBoxValueChangedEventArgs args)
39+
{
40+
ViewModel.SelectedAddress = AddressNumberBox.Value ?? 0;
41+
}
3042
}

src/UI/Windows/Views/Pages/ManagePage.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private void SetCommunicationActionControl()
108108
{
109109
ViewModel.DeviceActionParameter = new CommunicationParameters(
110110
ViewModel.ConnectedPortName, (uint)actionControl.SelectedBaudRate,
111-
actionControl.SelectedAddress);
111+
(byte)actionControl.SelectedAddress);
112112
};
113113
DeviceActionControl.Children.Add(actionControl);
114114
}

0 commit comments

Comments
 (0)