1
- //
1
+ //
2
2
// Copyright (c) .NET Foundation and Contributors
3
3
// See LICENSE file in the project root for full license information.
4
4
//
5
5
6
- using GalaSoft . MvvmLight ;
7
6
using nanoFramework . ANT . Services . NanoFrameworkService ;
8
7
using nanoFramework . Tools . Debugger ;
9
8
using nanoFramework . Tools . Debugger . WireProtocol ;
10
- using PropertyChanged ;
11
9
using System ;
12
10
using System . Collections . Generic ;
13
11
using System . Collections . ObjectModel ;
16
14
using System . Windows ;
17
15
using System . Windows . Data ;
18
16
using System . Windows . Threading ;
17
+ using CommunityToolkit . Mvvm . ComponentModel ;
19
18
20
19
namespace Serial_Test_App_WPF . ViewModel
21
20
{
@@ -31,12 +30,15 @@ namespace Serial_Test_App_WPF.ViewModel
31
30
/// See http://www.galasoft.ch/mvvm
32
31
/// </para>
33
32
/// </summary>
34
- [ AddINotifyPropertyChangedInterface ]
35
- public class MainViewModel : ViewModelBase
33
+ public class MainViewModel : ObservableObject
36
34
{
37
35
private readonly object _lockObj = new object ( ) ;
38
36
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 ;
40
42
41
43
/// <summary>
42
44
/// Initializes a new instance of the MainViewModel class.
@@ -53,34 +55,24 @@ public MainViewModel()
53
55
////}
54
56
}
55
57
56
- public INFSerialDebugClientService SerialDebugService
57
- {
58
- get
59
- {
60
- return _serialDebugService ;
61
- }
62
-
58
+ public INFSerialDebugClientService SerialDebugService
59
+ {
60
+ get => _serialDebugService ;
63
61
set
64
62
{
65
- if ( _serialDebugService == value )
63
+ if ( SetProperty ( ref _serialDebugService , value ) )
66
64
{
67
- return ;
68
- }
65
+ SelectedTransportType = TransportType . Serial ;
69
66
70
- _serialDebugService = value ;
67
+ AvailableDevices = _serialDebugService . SerialDebugClient . NanoFrameworkDevices ;
71
68
72
- RaisePropertyChanged ( "SerialDebugService" ) ;
69
+ // need to do this in order to allow sync from another thread
70
+ BindingOperations . EnableCollectionSynchronization ( AvailableDevices , _lockObj ) ;
73
71
74
- SelectedTransportType = TransportType . Serial ;
72
+ SerialDebugService . SerialDebugClient . NanoFrameworkDevices . CollectionChanged += NanoFrameworkDevices_CollectionChanged ;
75
73
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
+ }
84
76
}
85
77
}
86
78
@@ -95,7 +87,7 @@ private void SerialDebugClient_LogMessageAvailable1(object sender, StringEventAr
95
87
}
96
88
catch
97
89
{
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
99
91
}
100
92
}
101
93
@@ -106,7 +98,11 @@ private void SerialDebugClient_LogMessageAvailable(object sender, StringEventArg
106
98
} ) ) ;
107
99
}
108
100
109
- public ObservableCollection < NanoDeviceBase > AvailableDevices { get ; set ; }
101
+ public ObservableCollection < NanoDeviceBase > AvailableDevices
102
+ {
103
+ get => _availableDevices ;
104
+ set => SetProperty ( ref _availableDevices , value ) ;
105
+ }
110
106
111
107
private void NanoFrameworkDevices_CollectionChanged ( object sender , System . Collections . Specialized . NotifyCollectionChangedEventArgs e )
112
108
{
@@ -119,7 +115,6 @@ private void NanoFrameworkDevices_CollectionChanged(object sender, System.Collec
119
115
// break;
120
116
121
117
case TransportType . Serial :
122
-
123
118
break ;
124
119
125
120
default :
@@ -129,17 +124,27 @@ private void NanoFrameworkDevices_CollectionChanged(object sender, System.Collec
129
124
130
125
// if there's just one, select it
131
126
SelectedDevice = ( AvailableDevices . Count == 1 ) ? AvailableDevices . First ( ) : null ;
132
-
133
127
} ) ) ;
134
128
}
135
129
136
- public NanoDeviceBase SelectedDevice { get ; set ; }
130
+ public NanoDeviceBase SelectedDevice
131
+ {
132
+ get => _selectedDevice ;
133
+ set => SetProperty ( ref _selectedDevice , value ) ;
134
+ }
137
135
138
136
#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
+ }
142
142
143
+ public TransportType SelectedTransportType
144
+ {
145
+ get => _selectedTransportType ;
146
+ set => SetProperty ( ref _selectedTransportType , value ) ;
147
+ }
143
148
#endregion
144
149
}
145
- }
150
+ }
0 commit comments