Skip to content

Commit 2636287

Browse files
Upgraded VS Extension to use WPF-UI 4.0.0 (#1344)
* Upgraded VS Extension to use WPF-UI 4.0.0 * Delete src/src.sln --------- Co-authored-by: pomian <[email protected]>
1 parent 3742256 commit 2636287

File tree

23 files changed

+70
-153
lines changed

23 files changed

+70
-153
lines changed

src/Wpf.Ui.Extension.Template.Blank/App.xaml.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@ public partial class App
2727
}).Build();
2828

2929
/// <summary>
30-
/// Gets registered service.
30+
/// Gets services.
3131
/// </summary>
32-
/// <typeparam name="T">Type of the service to get.</typeparam>
33-
/// <returns>Instance of the service or <see langword="null"/>.</returns>
34-
public static T GetService<T>()
35-
where T : class
32+
public static IServiceProvider Services
3633
{
37-
return _host.Services.GetService(typeof(T)) as T;
34+
get { return _host.Services; }
3835
}
3936

4037
/// <summary>
4138
/// Occurs when the application is loading.
4239
/// </summary>
43-
private void OnStartup(object sender, StartupEventArgs e)
40+
private async void OnStartup(object sender, StartupEventArgs e)
4441
{
45-
_host.Start();
42+
await _host.StartAsync();
4643
}
4744

4845
/// <summary>

src/Wpf.Ui.Extension.Template.Blank/Wpf.Ui.Blank.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net8.0-windows</TargetFramework>
5+
<TargetFramework>net9.0-windows</TargetFramework>
66
<ApplicationManifest>app.manifest</ApplicationManifest>
77
<ApplicationIcon>wpfui-icon.ico</ApplicationIcon>
88
<UseWPF>true</UseWPF>
@@ -15,9 +15,9 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="WPF-UI" Version="3.0.5" />
19-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0 " />
20-
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2 "/>
18+
<PackageReference Include="WPF-UI" Version="4.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
20+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0 "/>
2121
</ItemGroup>
2222

2323
<ItemGroup>

src/Wpf.Ui.Extension.Template.Compact/App.xaml.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using $safeprojectname$.Views.Pages;
1111
using $safeprojectname$.Views.Windows;
1212
using Wpf.Ui;
13+
using Wpf.Ui.DependencyInjection;
1314

1415
namespace $safeprojectname$
1516
{
@@ -28,10 +29,9 @@ public partial class App
2829
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
2930
.ConfigureServices((context, services) =>
3031
{
31-
services.AddHostedService<ApplicationHostService>();
32+
services.AddNavigationViewPageProvider();
3233

33-
// Page resolver service
34-
services.AddSingleton<IPageService, PageService>();
34+
services.AddHostedService<ApplicationHostService>();
3535

3636
// Theme manipulation
3737
services.AddSingleton<IThemeService, ThemeService>();
@@ -55,22 +55,19 @@ public partial class App
5555
}).Build();
5656

5757
/// <summary>
58-
/// Gets registered service.
58+
/// Gets services.
5959
/// </summary>
60-
/// <typeparam name="T">Type of the service to get.</typeparam>
61-
/// <returns>Instance of the service or <see langword="null"/>.</returns>
62-
public static T GetService<T>()
63-
where T : class
60+
public static IServiceProvider Services
6461
{
65-
return _host.Services.GetService(typeof(T)) as T;
62+
get { return _host.Services; }
6663
}
6764

6865
/// <summary>
6966
/// Occurs when the application is loading.
7067
/// </summary>
71-
private void OnStartup(object sender, StartupEventArgs e)
68+
private async void OnStartup(object sender, StartupEventArgs e)
7269
{
73-
_host.Start();
70+
await _host.StartAsync();
7471
}
7572

7673
/// <summary>

src/Wpf.Ui.Extension.Template.Compact/Services/PageService.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Wpf.Ui.Extension.Template.Compact/ViewModels/Pages/DataViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Windows.Media;
22
using $safeprojectname$.Models;
3-
using Wpf.Ui.Controls;
3+
using Wpf.Ui.Abstractions.Controls;
44

55
namespace $safeprojectname$.ViewModels.Pages
66
{
@@ -11,13 +11,15 @@ public partial class DataViewModel : ObservableObject, INavigationAware
1111
[ObservableProperty]
1212
private IEnumerable<DataColor> _colors;
1313

14-
public void OnNavigatedTo()
14+
public Task OnNavigatedToAsync()
1515
{
1616
if (!_isInitialized)
1717
InitializeViewModel();
18+
19+
return Task.CompletedTask;
1820
}
1921

20-
public void OnNavigatedFrom() { }
22+
public Task OnNavigatedFromAsync() => Task.CompletedTask;
2123

2224
private void InitializeViewModel()
2325
{

src/Wpf.Ui.Extension.Template.Compact/ViewModels/Pages/SettingsViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Wpf.Ui.Appearance;
2-
using Wpf.Ui.Controls;
2+
using Wpf.Ui.Abstractions.Controls;
33

44
namespace $safeprojectname$.ViewModels.Pages
55
{
@@ -13,13 +13,15 @@ public partial class SettingsViewModel : ObservableObject, INavigationAware
1313
[ObservableProperty]
1414
private ApplicationTheme _currentTheme = ApplicationTheme.Unknown;
1515

16-
public void OnNavigatedTo()
16+
public Task OnNavigatedToAsync()
1717
{
1818
if (!_isInitialized)
1919
InitializeViewModel();
20+
21+
return Task.CompletedTask;
2022
}
2123

22-
public void OnNavigatedFrom() { }
24+
public Task OnNavigatedFromAsync() => Task.CompletedTask;
2325

2426
private void InitializeViewModel()
2527
{

src/Wpf.Ui.Extension.Template.Compact/Views/Pages/DashboardPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using $safeprojectname$.ViewModels.Pages;
2-
using Wpf.Ui.Controls;
2+
using Wpf.Ui.Abstractions.Controls;
33

44
namespace $safeprojectname$.Views.Pages
55
{

src/Wpf.Ui.Extension.Template.Compact/Views/Pages/DataPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using $safeprojectname$.ViewModels.Pages;
2-
using Wpf.Ui.Controls;
2+
using Wpf.Ui.Abstractions.Controls;
33

44
namespace $safeprojectname$.Views.Pages
55
{

src/Wpf.Ui.Extension.Template.Compact/Views/Pages/SettingsPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using $safeprojectname$.ViewModels.Pages;
2-
using Wpf.Ui.Controls;
2+
using Wpf.Ui.Abstractions.Controls;
33

44
namespace $safeprojectname$.Views.Pages
55
{

src/Wpf.Ui.Extension.Template.Compact/Views/Windows/MainWindow.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using $safeprojectname$.ViewModels.Windows;
22
using Wpf.Ui;
3+
using Wpf.Ui.Abstractions;
34
using Wpf.Ui.Appearance;
45
using Wpf.Ui.Controls;
56

@@ -11,7 +12,7 @@ public partial class MainWindow : INavigationWindow
1112

1213
public MainWindow(
1314
MainWindowViewModel viewModel,
14-
IPageService pageService,
15+
INavigationViewPageProvider navigationViewPageProvider,
1516
INavigationService navigationService
1617
)
1718
{
@@ -21,7 +22,7 @@ INavigationService navigationService
2122
SystemThemeWatcher.Watch(this);
2223

2324
InitializeComponent();
24-
SetPageService(pageService);
25+
SetPageService(navigationViewPageProvider);
2526

2627
navigationService.SetNavigationControl(RootNavigation);
2728
}
@@ -32,7 +33,7 @@ INavigationService navigationService
3233

3334
public bool Navigate(Type pageType) => RootNavigation.Navigate(pageType);
3435

35-
public void SetPageService(IPageService pageService) => RootNavigation.SetPageService(pageService);
36+
public void SetPageService(INavigationViewPageProvider navigationViewPageProvider) => RootNavigation.SetPageProviderService(navigationViewPageProvider);
3637

3738
public void ShowWindow() => Show();
3839

0 commit comments

Comments
 (0)