Skip to content

Commit 03cbc11

Browse files
committed
Migrated demo project from deprecated MvvmLight library to CommunityToolkit.Mvvm.
1 parent e1a2555 commit 03cbc11

9 files changed

+45
-38
lines changed

Demo/Demo.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="CommonServiceLocator" Version="2.0.5" />
19-
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
19+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
20+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
2021
</ItemGroup>
2122

2223
<ItemGroup>

Demo/SampleData/SampleViewModelPinnedTabExampleWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Collections.ObjectModel;
33
using System.Linq;
4+
using CommunityToolkit.Mvvm.Input;
45
using Demo.ViewModel;
5-
using GalaSoft.MvvmLight.Command;
66

77
namespace Demo.SampleData
88
{

Demo/ViewModel/IViewModelPinnedTabExampleWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using GalaSoft.MvvmLight.Command;
1+
using CommunityToolkit.Mvvm.Input;
22

33
namespace Demo.ViewModel
44
{

Demo/ViewModel/TabBase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System.Windows.Media;
2-
using GalaSoft.MvvmLight;
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using System.Windows.Media;
33

44
namespace Demo.ViewModel
55
{
6-
public abstract class TabBase : ViewModelBase
6+
public abstract class TabBase : ObservableRecipient
77
{
88
private int _tabNumber;
99
public int TabNumber
@@ -13,7 +13,7 @@ public int TabNumber
1313
{
1414
if (_tabNumber != value)
1515
{
16-
Set(() => TabNumber, ref _tabNumber, value);
16+
SetProperty(ref _tabNumber, value);
1717
}
1818
}
1919
}
@@ -26,7 +26,7 @@ public string TabName
2626
{
2727
if (_tabName != value)
2828
{
29-
Set(() => TabName, ref _tabName, value);
29+
SetProperty(ref _tabName, value);
3030
}
3131
}
3232
}
@@ -40,7 +40,7 @@ public bool IsPinned
4040
{
4141
if (_isPinned != value)
4242
{
43-
Set(() => IsPinned, ref _isPinned, value);
43+
SetProperty(ref _isPinned, value);
4444
}
4545
}
4646
}
@@ -54,7 +54,7 @@ public ImageSource TabIcon
5454
{
5555
if (!Equals(_tabIcon, value))
5656
{
57-
Set(() => TabIcon, ref _tabIcon, value);
57+
SetProperty(ref _tabIcon, value);
5858
}
5959
}
6060
}

Demo/ViewModel/TabClass4.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public bool IsBlinking
1111
{
1212
if (_isBlinking != value)
1313
{
14-
Set(() => IsBlinking, ref _isBlinking, value);
14+
SetProperty(ref _isBlinking, value);
1515
}
1616
}
1717
}

Demo/ViewModel/ViewModelExampleBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
using System.Windows.Data;
77
using System.Windows.Media.Imaging;
88
using ChromeTabs;
9+
using CommunityToolkit.Mvvm.ComponentModel;
10+
using CommunityToolkit.Mvvm.Input;
911
using Demo.Properties;
10-
using GalaSoft.MvvmLight;
11-
using GalaSoft.MvvmLight.Command;
1212

1313
namespace Demo.ViewModel
1414
{
15-
public class ViewModelExampleBase : ViewModelBase
15+
public class ViewModelExampleBase : ObservableRecipient
1616
{
1717
//since we don't know what kind of objects are bound, so the sorting happens outside with the ReorderTabsCommand.
1818
public RelayCommand<TabReorder> ReorderTabsCommand { get; set; }
@@ -29,7 +29,7 @@ public TabBase SelectedTab
2929
{
3030
if (_selectedTab != value)
3131
{
32-
Set(() => SelectedTab, ref _selectedTab, value);
32+
SetProperty(ref _selectedTab, value);
3333
}
3434
}
3535
}
@@ -41,8 +41,8 @@ public bool CanAddTabs
4141
set
4242
{
4343
if (_canAddTabs == value) return;
44-
Set(() => CanAddTabs, ref _canAddTabs, value);
45-
AddTabCommand.RaiseCanExecuteChanged();
44+
SetProperty(ref _canAddTabs, value);
45+
AddTabCommand.NotifyCanExecuteChanged();
4646
}
4747
}
4848

Demo/ViewModel/ViewModelLocator.cs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
*/
1414

1515
using CommonServiceLocator;
16-
using GalaSoft.MvvmLight;
17-
using GalaSoft.MvvmLight.Ioc;
16+
using CommunityToolkit.Mvvm.DependencyInjection;
17+
using Microsoft.Extensions.DependencyInjection;
18+
using System.ComponentModel;
19+
using System.Windows.Navigation;
20+
1821

1922
namespace Demo.ViewModel
2023
{
@@ -29,51 +32,54 @@ public class ViewModelLocator
2932
/// </summary>
3033
public ViewModelLocator()
3134
{
32-
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
33-
34-
if (ViewModelBase.IsInDesignModeStatic)
35+
if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
3536
{
3637
// Create design time view services and models
37-
SimpleIoc.Default.Register<IViewModelMainWindow, SampleData.SampleViewModelMainWindow>();
38-
SimpleIoc.Default.Register<IViewModelPinnedTabExampleWindow, SampleData.SampleViewModelPinnedTabExampleWindow>();
39-
SimpleIoc.Default.Register<IViewModelCustomStyleExampleWindow, SampleData.SampleViewModelCustomStyleExampleWindow>();
38+
Ioc.Default.ConfigureServices(
39+
new ServiceCollection()
40+
.AddSingleton<IViewModelMainWindow, SampleData.SampleViewModelMainWindow>()
41+
.AddSingleton<IViewModelPinnedTabExampleWindow, SampleData.SampleViewModelPinnedTabExampleWindow>()
42+
.AddSingleton<IViewModelCustomStyleExampleWindow, SampleData.SampleViewModelCustomStyleExampleWindow>()
43+
.BuildServiceProvider());
4044
}
4145
else
4246
{
4347
// Create run time view services and models
44-
SimpleIoc.Default.Register<IViewModelMainWindow, ViewModelMainWindow>();
45-
SimpleIoc.Default.Register<IViewModelPinnedTabExampleWindow, ViewModelPinnedTabExampleWindow>();
46-
SimpleIoc.Default.Register<IViewModelCustomStyleExampleWindow, ViewModelCustomStyleExampleWindow>();
48+
Ioc.Default.ConfigureServices(
49+
new ServiceCollection()
50+
.AddSingleton<IViewModelMainWindow, ViewModelMainWindow>()
51+
.AddSingleton<IViewModelPinnedTabExampleWindow, ViewModelPinnedTabExampleWindow>()
52+
.AddSingleton<IViewModelCustomStyleExampleWindow, ViewModelCustomStyleExampleWindow>()
53+
.BuildServiceProvider());
4754
}
48-
4955
}
5056

5157
public IViewModelCustomStyleExampleWindow VieWModelCustomStyleExampleWindow
5258
{
53-
get
59+
get
5460
{
55-
return ServiceLocator.Current.GetInstance<IViewModelCustomStyleExampleWindow>();
61+
return Ioc.Default.GetService<IViewModelCustomStyleExampleWindow>();
5662
}
5763
}
5864

5965
public IViewModelMainWindow ViewModelMainWindow
6066
{
6167
get
6268
{
63-
return ServiceLocator.Current.GetInstance<IViewModelMainWindow>();
69+
return Ioc.Default.GetService<IViewModelMainWindow>();
6470
}
6571
}
6672

6773
public IViewModelPinnedTabExampleWindow ViewModelPinnedTabExampleWindow
6874
{
6975
get
7076
{
71-
return ServiceLocator.Current.GetInstance<IViewModelPinnedTabExampleWindow>();
77+
return Ioc.Default.GetService<IViewModelPinnedTabExampleWindow>();
7278
}
7379

7480
}
7581

76-
82+
7783
public static void Cleanup()
7884
{
7985
// TODO Clear the ViewModels

Demo/ViewModel/ViewModelMainWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public bool CanMoveTabs
1515
{
1616
if (_canMoveTabs != value)
1717
{
18-
Set(() => CanMoveTabs, ref _canMoveTabs, value);
18+
SetProperty(ref _canMoveTabs, value);
1919
}
2020
}
2121
}
@@ -28,7 +28,7 @@ public bool ShowAddButton
2828
{
2929
if (_showAddButton != value)
3030
{
31-
Set(() => ShowAddButton, ref _showAddButton, value);
31+
SetProperty(ref _showAddButton, value);
3232
}
3333
}
3434
}

Demo/ViewModel/ViewModelPinnedTabExampleWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.ComponentModel;
1+
using CommunityToolkit.Mvvm.Input;
2+
using System.ComponentModel;
23
using System.Linq;
34
using System.Windows.Data;
4-
using GalaSoft.MvvmLight.Command;
55

66
namespace Demo.ViewModel
77
{

0 commit comments

Comments
 (0)