Skip to content

Commit

Permalink
Upgraded VS Extension to use WPF-UI 4.0.0 (#1344)
Browse files Browse the repository at this point in the history
* Upgraded VS Extension to use WPF-UI 4.0.0

* Delete src/src.sln

---------

Co-authored-by: pomian <[email protected]>
  • Loading branch information
Djohnnie and pomianowski authored Feb 16, 2025
1 parent 3742256 commit 2636287
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 153 deletions.
13 changes: 5 additions & 8 deletions src/Wpf.Ui.Extension.Template.Blank/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ public partial class App
}).Build();

/// <summary>
/// Gets registered service.
/// Gets services.
/// </summary>
/// <typeparam name="T">Type of the service to get.</typeparam>
/// <returns>Instance of the service or <see langword="null"/>.</returns>
public static T GetService<T>()
where T : class
public static IServiceProvider Services
{
return _host.Services.GetService(typeof(T)) as T;
get { return _host.Services; }
}

/// <summary>
/// Occurs when the application is loading.
/// </summary>
private void OnStartup(object sender, StartupEventArgs e)
private async void OnStartup(object sender, StartupEventArgs e)
{
_host.Start();
await _host.StartAsync();
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Wpf.Ui.Extension.Template.Blank/Wpf.Ui.Blank.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>wpfui-icon.ico</ApplicationIcon>
<UseWPF>true</UseWPF>
Expand All @@ -15,9 +15,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0 " />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2 "/>
<PackageReference Include="WPF-UI" Version="4.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0 "/>
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 8 additions & 11 deletions src/Wpf.Ui.Extension.Template.Compact/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using $safeprojectname$.Views.Pages;
using $safeprojectname$.Views.Windows;
using Wpf.Ui;
using Wpf.Ui.DependencyInjection;

namespace $safeprojectname$
{
Expand All @@ -28,10 +29,9 @@ public partial class App
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
.ConfigureServices((context, services) =>
{
services.AddHostedService<ApplicationHostService>();
services.AddNavigationViewPageProvider();

// Page resolver service
services.AddSingleton<IPageService, PageService>();
services.AddHostedService<ApplicationHostService>();

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

/// <summary>
/// Gets registered service.
/// Gets services.
/// </summary>
/// <typeparam name="T">Type of the service to get.</typeparam>
/// <returns>Instance of the service or <see langword="null"/>.</returns>
public static T GetService<T>()
where T : class
public static IServiceProvider Services
{
return _host.Services.GetService(typeof(T)) as T;
get { return _host.Services; }
}

/// <summary>
/// Occurs when the application is loading.
/// </summary>
private void OnStartup(object sender, StartupEventArgs e)
private async void OnStartup(object sender, StartupEventArgs e)
{
_host.Start();
await _host.StartAsync();
}

/// <summary>
Expand Down
42 changes: 0 additions & 42 deletions src/Wpf.Ui.Extension.Template.Compact/Services/PageService.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Windows.Media;
using $safeprojectname$.Models;
using Wpf.Ui.Controls;
using Wpf.Ui.Abstractions.Controls;

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

public void OnNavigatedTo()
public Task OnNavigatedToAsync()
{
if (!_isInitialized)
InitializeViewModel();

return Task.CompletedTask;
}

public void OnNavigatedFrom() { }
public Task OnNavigatedFromAsync() => Task.CompletedTask;

private void InitializeViewModel()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;
using Wpf.Ui.Abstractions.Controls;

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

public void OnNavigatedTo()
public Task OnNavigatedToAsync()
{
if (!_isInitialized)
InitializeViewModel();

return Task.CompletedTask;
}

public void OnNavigatedFrom() { }
public Task OnNavigatedFromAsync() => Task.CompletedTask;

private void InitializeViewModel()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using $safeprojectname$.ViewModels.Pages;
using Wpf.Ui.Controls;
using Wpf.Ui.Abstractions.Controls;

namespace $safeprojectname$.Views.Pages
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using $safeprojectname$.ViewModels.Pages;
using Wpf.Ui.Controls;
using Wpf.Ui.Abstractions.Controls;

namespace $safeprojectname$.Views.Pages
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using $safeprojectname$.ViewModels.Pages;
using Wpf.Ui.Controls;
using Wpf.Ui.Abstractions.Controls;

namespace $safeprojectname$.Views.Pages
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using $safeprojectname$.ViewModels.Windows;
using Wpf.Ui;
using Wpf.Ui.Abstractions;
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;

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

public MainWindow(
MainWindowViewModel viewModel,
IPageService pageService,
INavigationViewPageProvider navigationViewPageProvider,
INavigationService navigationService
)
{
Expand All @@ -21,7 +22,7 @@ INavigationService navigationService
SystemThemeWatcher.Watch(this);

InitializeComponent();
SetPageService(pageService);
SetPageService(navigationViewPageProvider);

navigationService.SetNavigationControl(RootNavigation);
}
Expand All @@ -32,7 +33,7 @@ INavigationService navigationService

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

public void SetPageService(IPageService pageService) => RootNavigation.SetPageService(pageService);
public void SetPageService(INavigationViewPageProvider navigationViewPageProvider) => RootNavigation.SetPageProviderService(navigationViewPageProvider);

public void ShowWindow() => Show();

Expand Down
9 changes: 5 additions & 4 deletions src/Wpf.Ui.Extension.Template.Compact/Wpf.Ui.Compact.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>wpfui-icon.ico</ApplicationIcon>
<UseWPF>true</UseWPF>
Expand All @@ -15,9 +15,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0 " />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2 "/>
<PackageReference Include="WPF-UI" Version="4.0.0" />
<PackageReference Include="WPF-UI.DependencyInjection" Version="4.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0 "/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
</Folder>
<Folder Name="Services" TargetFolderName="Services">
<ProjectItem ReplaceParameters="true" TargetFileName="ApplicationHostService.cs">ApplicationHostService.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="PageService.cs">PageService.cs</ProjectItem>
</Folder>
<Folder Name="ViewModels" TargetFolderName="ViewModels">
<Folder Name="Pages" TargetFolderName="Pages">
Expand Down
19 changes: 8 additions & 11 deletions src/Wpf.Ui.Extension.Template.Fluent/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using $safeprojectname$.Views.Pages;
using $safeprojectname$.Views.Windows;
using Wpf.Ui;
using Wpf.Ui.DependencyInjection;

namespace $safeprojectname$
{
Expand All @@ -28,10 +29,9 @@ public partial class App
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)); })
.ConfigureServices((context, services) =>
{
services.AddHostedService<ApplicationHostService>();
services.AddNavigationViewPageProvider();

// Page resolver service
services.AddSingleton<IPageService, PageService>();
services.AddHostedService<ApplicationHostService>();

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

/// <summary>
/// Gets registered service.
/// Gets services.
/// </summary>
/// <typeparam name="T">Type of the service to get.</typeparam>
/// <returns>Instance of the service or <see langword="null"/>.</returns>
public static T GetService<T>()
where T : class
public static IServiceProvider Services
{
return _host.Services.GetService(typeof(T)) as T;
get { return _host.Services; }
}

/// <summary>
/// Occurs when the application is loading.
/// </summary>
private void OnStartup(object sender, StartupEventArgs e)
private async void OnStartup(object sender, StartupEventArgs e)
{
_host.Start();
await _host.StartAsync();
}

/// <summary>
Expand Down
42 changes: 0 additions & 42 deletions src/Wpf.Ui.Extension.Template.Fluent/Services/PageService.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Windows.Media;
using $safeprojectname$.Models;
using Wpf.Ui.Controls;
using Wpf.Ui.Abstractions.Controls;

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

public void OnNavigatedTo()
public Task OnNavigatedToAsync()
{
if (!_isInitialized)
InitializeViewModel();

return Task.CompletedTask;
}

public void OnNavigatedFrom() { }
public Task OnNavigatedFromAsync() => Task.CompletedTask;

private void InitializeViewModel()
{
Expand Down
Loading

0 comments on commit 2636287

Please sign in to comment.