1- //
1+ //
22// Copyright (c) .NET Foundation and Contributors
33// See LICENSE file in the project root for full license information.
44//
55
6- using GalaSoft . MvvmLight ;
76using nanoFramework . ANT . Services . NanoFrameworkService ;
87using nanoFramework . Tools . Debugger ;
98using nanoFramework . Tools . Debugger . WireProtocol ;
10- using PropertyChanged ;
119using System ;
1210using System . Collections . Generic ;
1311using System . Collections . ObjectModel ;
1614using System . Windows ;
1715using System . Windows . Data ;
1816using System . Windows . Threading ;
17+ using CommunityToolkit . Mvvm . ComponentModel ;
1918
2019namespace Serial_Test_App_WPF . ViewModel
2120{
@@ -31,12 +30,15 @@ namespace Serial_Test_App_WPF.ViewModel
3130 /// See http://www.galasoft.ch/mvvm
3231 /// </para>
3332 /// </summary>
34- [ AddINotifyPropertyChangedInterface ]
35- public class MainViewModel : ViewModelBase
33+ public class MainViewModel : ObservableObject
3634 {
3735 private readonly object _lockObj = new object ( ) ;
3836
39- INFSerialDebugClientService _serialDebugService ;
37+ private INFSerialDebugClientService _serialDebugService ;
38+ private ObservableCollection < NanoDeviceBase > _availableDevices ;
39+ private NanoDeviceBase _selectedDevice ;
40+ private List < TransportType > _availableTransportTypes ;
41+ private TransportType _selectedTransportType ;
4042
4143 /// <summary>
4244 /// Initializes a new instance of the MainViewModel class.
@@ -53,34 +55,24 @@ public MainViewModel()
5355 ////}
5456 }
5557
56- public INFSerialDebugClientService SerialDebugService
57- {
58- get
59- {
60- return _serialDebugService ;
61- }
62-
58+ public INFSerialDebugClientService SerialDebugService
59+ {
60+ get => _serialDebugService ;
6361 set
6462 {
65- if ( _serialDebugService == value )
63+ if ( SetProperty ( ref _serialDebugService , value ) )
6664 {
67- return ;
68- }
65+ SelectedTransportType = TransportType . Serial ;
6966
70- _serialDebugService = value ;
67+ AvailableDevices = _serialDebugService . SerialDebugClient . NanoFrameworkDevices ;
7168
72- RaisePropertyChanged ( "SerialDebugService" ) ;
69+ // need to do this in order to allow sync from another thread
70+ BindingOperations . EnableCollectionSynchronization ( AvailableDevices , _lockObj ) ;
7371
74- SelectedTransportType = TransportType . Serial ;
72+ SerialDebugService . SerialDebugClient . NanoFrameworkDevices . CollectionChanged += NanoFrameworkDevices_CollectionChanged ;
7573
76- AvailableDevices = _serialDebugService . SerialDebugClient . NanoFrameworkDevices ;
77-
78- // need to do this in order to allow sync from another thread
79- BindingOperations . EnableCollectionSynchronization ( AvailableDevices , _lockObj ) ;
80-
81- SerialDebugService . SerialDebugClient . NanoFrameworkDevices . CollectionChanged += NanoFrameworkDevices_CollectionChanged ;
82-
83- SerialDebugService . SerialDebugClient . LogMessageAvailable += SerialDebugClient_LogMessageAvailable1 ;
74+ SerialDebugService . SerialDebugClient . LogMessageAvailable += SerialDebugClient_LogMessageAvailable1 ;
75+ }
8476 }
8577 }
8678
@@ -95,7 +87,7 @@ private void SerialDebugClient_LogMessageAvailable1(object sender, StringEventAr
9587 }
9688 catch
9789 {
98- // catch all as the dispatcher is ont always available and that's OK
90+ // catch all as the dispatcher is not always available and that's OK
9991 }
10092 }
10193
@@ -106,7 +98,11 @@ private void SerialDebugClient_LogMessageAvailable(object sender, StringEventArg
10698 } ) ) ;
10799 }
108100
109- public ObservableCollection < NanoDeviceBase > AvailableDevices { get ; set ; }
101+ public ObservableCollection < NanoDeviceBase > AvailableDevices
102+ {
103+ get => _availableDevices ;
104+ set => SetProperty ( ref _availableDevices , value ) ;
105+ }
110106
111107 private void NanoFrameworkDevices_CollectionChanged ( object sender , System . Collections . Specialized . NotifyCollectionChangedEventArgs e )
112108 {
@@ -119,7 +115,6 @@ private void NanoFrameworkDevices_CollectionChanged(object sender, System.Collec
119115 // break;
120116
121117 case TransportType . Serial :
122-
123118 break ;
124119
125120 default :
@@ -129,17 +124,27 @@ private void NanoFrameworkDevices_CollectionChanged(object sender, System.Collec
129124
130125 // if there's just one, select it
131126 SelectedDevice = ( AvailableDevices . Count == 1 ) ? AvailableDevices . First ( ) : null ;
132-
133127 } ) ) ;
134128 }
135129
136- public NanoDeviceBase SelectedDevice { get ; set ; }
130+ public NanoDeviceBase SelectedDevice
131+ {
132+ get => _selectedDevice ;
133+ set => SetProperty ( ref _selectedDevice , value ) ;
134+ }
137135
138136 #region Transport
139- public List < TransportType > AvailableTransportTypes { get ; set ; }
140-
141- public TransportType SelectedTransportType { get ; set ; }
137+ public List < TransportType > AvailableTransportTypes
138+ {
139+ get => _availableTransportTypes ;
140+ set => SetProperty ( ref _availableTransportTypes , value ) ;
141+ }
142142
143+ public TransportType SelectedTransportType
144+ {
145+ get => _selectedTransportType ;
146+ set => SetProperty ( ref _selectedTransportType , value ) ;
147+ }
143148 #endregion
144149 }
145- }
150+ }
0 commit comments