Skip to content

Commit fc048fe

Browse files
authored
Migrate to CommunityToolkit.Mvvm (#379)
1 parent da33fae commit fc048fe

31 files changed

+830
-678
lines changed

README-BEFORE-UPDATE-REFS.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Notes on updating the project references:
2+
3+
IMPORTANT VERSION CONSTRAINTS:
4+
- System.Threading.Tasks.Extensions must not be updated beyond version 4.5.4
5+
Reason: The VS2019 extension will fail due to a transitive dependency conflict between
6+
Compilers.Services.Unsafe and System.Collections.Immutable.

USB Test App WPF/App.xaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Application x:Class="Serial_Test_App_WPF.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Serial_Test_App_WPF" StartupUri="MainWindow.xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
2-
<Application.Resources>
3-
<ResourceDictionary>
4-
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:Serial_Test_App_WPF.ViewModel" />
5-
</ResourceDictionary>
6-
</Application.Resources>
7-
</Application>
1+
<Application x:Class="Serial_Test_App_WPF.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Serial_Test_App_WPF" StartupUri="MainWindow.xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
2+
<Application.Resources>
3+
<ResourceDictionary>
4+
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:Serial_Test_App_WPF.ViewModel"/>
5+
</ResourceDictionary>
6+
</Application.Resources>
7+
</Application>

USB Test App WPF/App.xaml.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
// Copyright (c) .NET Foundation and Contributors
33
// See LICENSE file in the project root for full license information.
44
//
5+
//
6+
// Copyright (c) .NET Foundation and Contributors
7+
// See LICENSE file in the project root for full license information.
8+
//
59

610
using CommonServiceLocator;
711
using nanoFramework.ANT.Services.NanoFrameworkService;
812
using nanoFramework.Tools.Debugger;
913
using Serial_Test_App_WPF.ViewModel;
1014
using System;
1115
using System.Collections.Generic;
16+
using CommunityToolkit.Mvvm.DependencyInjection;
1217

1318
namespace Serial_Test_App_WPF
1419
{
@@ -27,12 +32,12 @@ public App()
2732
vml = new ViewModelLocator();
2833

2934
var serialClient = CreateSerialDebugClient();
30-
ServiceLocator.Current.GetInstance<MainViewModel>().SerialDebugService = serialClient;
35+
Ioc.Default.GetService<MainViewModel>().SerialDebugService = serialClient;
3136
}
3237

3338
private void App_Exit(object sender, System.Windows.ExitEventArgs e)
3439
{
35-
var serialClient = ServiceLocator.Current.GetInstance<MainViewModel>().SerialDebugService;
40+
var serialClient = Ioc.Default.GetService<MainViewModel>().SerialDebugService;
3641
serialClient.SerialDebugClient.StopDeviceWatchers();
3742
}
3843

USB Test App WPF/FodyWeavers.xml

-4
This file was deleted.

USB Test App WPF/FodyWeavers.xsd

-54
This file was deleted.

USB Test App WPF/MainWindow.xaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:Serial_Test_App_WPF"
7-
xmlns:ViewModel="clr-namespace:Serial_Test_App_WPF.ViewModel" x:Class="Serial_Test_App_WPF.MainWindow"
7+
xmlns:ViewModel="clr-namespace:Serial_Test_App_WPF.ViewModel"
8+
x:Class="Serial_Test_App_WPF.MainWindow"
89
mc:Ignorable="d"
910
Title="MainWindow" Height="374" Width="570.729">
1011
<Window.Resources>
@@ -54,7 +55,5 @@
5455
<Button Content="Reboot CLR" HorizontalAlignment="Left" Margin="364,77,0,0" VerticalAlignment="Top" Width="121" Click="RebootDeviceButton_Click"/>
5556
<Button Content="Upload File I:\" HorizontalAlignment="Left" Margin="39,306,0,0" VerticalAlignment="Top" Width="110" Click="UploadFileInternalStorage_Click"/>
5657
<Button Content="Rm file I:\" HorizontalAlignment="Left" Margin="162,306,0,0" VerticalAlignment="Top" Width="75" Click="RemoveFileInternalStorage_Click"/>
57-
58-
5958
</Grid>
6059
</Window>

USB Test App WPF/MainWindow.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ private void SetDeviceConfigButton_Click(object sender, RoutedEventArgs e)
855855
Password = "1234",
856856
Authentication = AuthenticationType.WPA2,
857857
Encryption = EncryptionType.WPA2,
858-
Options = Wireless80211_ConfigurationOptions.AutoConnect
858+
Wireless80211Options = Wireless80211_ConfigurationOptions.AutoConnect
859859
};
860860

861861
// write wireless configuration to device

USB Test App WPF/Serial Test App WPF.csproj

+7-9
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,20 @@
104104
<PackageReference Include="CommonServiceLocator">
105105
<Version>2.0.7</Version>
106106
</PackageReference>
107-
<PackageReference Include="Fody">
108-
<Version>4.2.1</Version>
109-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
110-
<PrivateAssets>all</PrivateAssets>
107+
<PackageReference Include="CommunityToolkit.Mvvm">
108+
<Version>8.3.2</Version>
111109
</PackageReference>
112-
<PackageReference Include="MvvmLight">
113-
<Version>5.4.1.1</Version>
110+
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
111+
<Version>6.0.2</Version>
114112
</PackageReference>
115113
<PackageReference Include="nanoFramework.CoreLibrary">
116114
<Version>1.14.2</Version>
117115
</PackageReference>
118-
<PackageReference Include="PropertyChanged.Fody">
119-
<Version>2.6.1</Version>
116+
<PackageReference Include="System.IO.Ports">
117+
<Version>8.0.0</Version>
120118
</PackageReference>
121119
<PackageReference Include="System.Threading.Tasks.Extensions">
122-
<Version>4.5.4</Version>
120+
<Version>4.6.0</Version>
123121
</PackageReference>
124122
<PackageReference Include="System.ValueTuple">
125123
<Version>4.5.0</Version>
+41-36
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
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;
76
using nanoFramework.ANT.Services.NanoFrameworkService;
87
using nanoFramework.Tools.Debugger;
98
using nanoFramework.Tools.Debugger.WireProtocol;
10-
using PropertyChanged;
119
using System;
1210
using System.Collections.Generic;
1311
using System.Collections.ObjectModel;
@@ -16,6 +14,7 @@
1614
using System.Windows;
1715
using System.Windows.Data;
1816
using System.Windows.Threading;
17+
using CommunityToolkit.Mvvm.ComponentModel;
1918

2019
namespace 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

Comments
 (0)