From d5ee557a44164941d2f1d259427e66b3b42ac865 Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Sun, 2 Jun 2024 23:49:08 +0200 Subject: [PATCH 01/13] Move code and add abstractions --- .github/workflows/wpf-ui-cd-nuget.yaml | 3 + Directory.Build.props | 62 +++++---- Directory.Build.targets | 101 +++++++++++++- LICENSE.md | 21 +++ ThirdPartyNotices.txt | 6 + Wpf.Ui.sln | 130 +++++++++++------- .../nuget.png | Bin .../Wpf.Ui.Demo.Console/GlobalUsings.cs | 0 .../Wpf.Ui.Demo.Console/Models/DataColor.cs | 0 .../Wpf.Ui.Demo.Console/Program.cs | 0 .../Utilities/ThemeUtilities.cs | 0 .../Wpf.Ui.Demo.Console/Views/MainView.xaml | 0 .../Views/MainView.xaml.cs | 0 .../Views/Pages/DashboardPage.xaml | 0 .../Views/Pages/DashboardPage.xaml.cs | 0 .../Views/Pages/DataPage.xaml | 0 .../Views/Pages/DataPage.xaml.cs | 0 .../Views/Pages/SettingsPage.xaml | 0 .../Views/Pages/SettingsPage.xaml.cs | 0 .../Wpf.Ui.Demo.Console/Views/SimpleView.xaml | 0 .../Views/SimpleView.xaml.cs | 0 .../Wpf.Ui.Demo.Console.csproj | 11 +- .../Wpf.Ui.Demo.Console/wpfui.ico | Bin {src => samples}/Wpf.Ui.Demo.Mvvm/App.xaml | 0 {src => samples}/Wpf.Ui.Demo.Mvvm/App.xaml.cs | 18 +-- samples/Wpf.Ui.Demo.Mvvm/AssemblyInfo.cs | 6 + .../Assets/applicationIcon-1024.png | Bin .../Assets/applicationIcon-256.png | Bin samples/Wpf.Ui.Demo.Mvvm/GlobalUsings.cs | 15 ++ .../Helpers/EnumToBooleanConverter.cs | 1 - .../Wpf.Ui.Demo.Mvvm/Models/AppConfig.cs | 0 .../Wpf.Ui.Demo.Mvvm/Models/DataColor.cs | 0 .../Services/ApplicationHostService.cs | 13 +- .../Wpf.Ui.Demo.Mvvm/Services/PageService.cs | 25 ++++ .../ViewModels/DashboardViewModel.cs | 4 +- .../ViewModels/DataViewModel.cs | 7 +- .../ViewModels/MainWindowViewModel.cs | 2 +- .../ViewModels/SettingsViewModel.cs | 8 +- .../Wpf.Ui.Demo.Mvvm/ViewModels/ViewModel.cs | 55 ++++++++ .../Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml | 0 .../Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml.cs | 1 + .../Views/Pages/DashboardPage.xaml | 0 .../Views/Pages/DashboardPage.xaml.cs | 4 +- .../Views/Pages/DataPage.xaml | 0 .../Views/Pages/DataPage.xaml.cs | 4 +- .../Views/Pages/SettingsPage.xaml | 0 .../Views/Pages/SettingsPage.xaml.cs | 4 +- .../Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj | 18 +-- .../Wpf.Ui.Demo.Mvvm/app.manifest | 0 .../Wpf.Ui.Demo.Mvvm/applicationIcon.ico | Bin {src => samples}/Wpf.Ui.Demo.Simple/App.xaml | 0 .../Wpf.Ui.Demo.Simple/App.xaml.cs | 0 .../Wpf.Ui.Demo.Simple/AssemblyInfo.cs | 0 .../Assets/applicationIcon-1024.png | Bin 0 -> 10779 bytes .../Assets/applicationIcon-256.png | Bin .../Wpf.Ui.Demo.Simple/MainWindow.xaml | 0 .../Wpf.Ui.Demo.Simple/MainWindow.xaml.cs | 0 .../Wpf.Ui.Demo.Simple/Models/DataColor.cs | 0 .../Views/Pages/DashboardPage.xaml | 0 .../Views/Pages/DashboardPage.xaml.cs | 0 .../Views/Pages/DataPage.xaml | 0 .../Views/Pages/DataPage.xaml.cs | 0 .../Views/Pages/SettingsPage.xaml | 0 .../Views/Pages/SettingsPage.xaml.cs | 0 .../Wpf.Ui.Demo.Simple.csproj | 18 +-- .../Wpf.Ui.Demo.Simple/app.manifest | 0 .../Wpf.Ui.Demo.Simple/applicationIcon.ico | Bin .../Controls}/INavigableView.cs | 7 +- .../Controls}/INavigationAware.cs | 14 +- .../Controls/NavigationAware.cs | 40 ++++++ src/Wpf.Ui.Abstractions/GlobalUsings.cs | 7 + src/Wpf.Ui.Abstractions/IPageService.cs | 19 +++ .../NavigationException.cs | 27 ++++ .../PageServiceExtensions.cs | 39 ++++++ .../Wpf.Ui.Abstractions.csproj | 18 +++ src/Wpf.Ui.Demo.Mvvm/AssemblyInfo.cs | 9 -- src/Wpf.Ui.Demo.Mvvm/Services/PageService.cs | 48 ------- src/Wpf.Ui.FontMapper/GitTag.cs | 2 +- src/Wpf.Ui.FontMapper/GlobalUsings.cs | 11 ++ src/Wpf.Ui.FontMapper/Program.cs | 2 +- .../ServiceCollectionExtensions.cs | 7 + .../{Usings.cs => GlobalUsings.cs} | 11 +- .../ViewModels/Pages/AllControlsViewModel.cs | 2 +- .../Pages/BasicInput/AnchorViewModel.cs | 2 +- .../Pages/BasicInput/BasicInputViewModel.cs | 2 +- .../Pages/BasicInput/ButtonViewModel.cs | 2 +- .../Pages/BasicInput/CheckBoxViewModel.cs | 2 +- .../Pages/BasicInput/ComboBoxViewModel.cs | 2 +- .../BasicInput/DropDownButtonViewModel.cs | 2 +- .../BasicInput/HyperlinkButtonViewModel.cs | 2 +- .../Pages/BasicInput/RadioButtonViewModel.cs | 2 +- .../Pages/BasicInput/RatingViewModel.cs | 2 +- .../Pages/BasicInput/SliderViewModel.cs | 2 +- .../Pages/BasicInput/SplitButtonViewModel.cs | 2 +- .../Pages/BasicInput/ThumbRateViewModel.cs | 2 +- .../Pages/BasicInput/ToggleButtonViewModel.cs | 2 +- .../Pages/BasicInput/ToggleSwitchViewModel.cs | 2 +- .../Pages/Collections/CollectionsViewModel.cs | 2 +- .../Pages/Collections/DataGridViewModel.cs | 9 +- .../Pages/Collections/ListBoxViewModel.cs | 16 ++- .../Pages/Collections/ListViewViewModel.cs | 9 +- .../Pages/Collections/TreeListViewModel.cs | 2 +- .../Pages/Collections/TreeViewViewModel.cs | 2 +- .../ViewModels/Pages/DashboardViewModel.cs | 11 +- .../CalendarDatePickerViewModel.cs | 2 +- .../Pages/DateAndTime/CalendarViewModel.cs | 2 +- .../Pages/DateAndTime/DateAndTimeViewModel.cs | 2 +- .../Pages/DateAndTime/DatePickerViewModel.cs | 2 +- .../Pages/DateAndTime/TimePickerViewModel.cs | 2 +- .../Pages/DesignGuidance/ColorsViewModel.cs | 2 +- .../Pages/DesignGuidance/IconsViewModel.cs | 6 +- .../DesignGuidance/TypographyViewModel.cs | 2 +- .../ContentDialogViewModel.cs | 13 +- .../DialogsAndFlyoutsViewModel.cs | 2 +- .../DialogsAndFlyouts/FlyoutViewModel.cs | 2 +- .../DialogsAndFlyouts/MessageBoxViewModel.cs | 2 +- .../DialogsAndFlyouts/SnackbarViewModel.cs | 2 +- .../Pages/Layout/CardActionViewModel.cs | 2 +- .../Pages/Layout/CardControlViewModel.cs | 2 +- .../Pages/Layout/ExpanderViewModel.cs | 2 +- .../Pages/Layout/LayoutViewModel.cs | 2 +- .../ViewModels/Pages/Media/CanvasViewModel.cs | 2 +- .../ViewModels/Pages/Media/ImageViewModel.cs | 2 +- .../ViewModels/Pages/Media/MediaViewModel.cs | 2 +- .../Pages/Media/WebBrowserViewModel.cs | 2 +- .../Pages/Media/WebViewViewModel.cs | 2 +- .../Navigation/BreadcrumbBarViewModel.cs | 2 +- .../Pages/Navigation/MenuViewModel.cs | 2 +- .../Pages/Navigation/NavigationViewModel.cs | 2 +- .../Navigation/NavigationViewViewModel.cs | 2 +- .../Pages/Navigation/TabControlViewModel.cs | 2 +- .../Pages/Navigation/TabViewViewModel.cs | 2 +- .../Pages/OpSystem/ClipboardViewModel.cs | 2 +- .../Pages/OpSystem/FilePickerViewModel.cs | 2 +- .../Pages/OpSystem/OpSystemViewModel.cs | 2 +- .../ViewModels/Pages/SettingsViewModel.cs | 15 +- .../Pages/StatusAndInfo/InfoBadgeViewModel.cs | 2 +- .../Pages/StatusAndInfo/InfoBarViewModel.cs | 2 +- .../StatusAndInfo/ProgressBarViewModel.cs | 2 +- .../StatusAndInfo/ProgressRingViewModel.cs | 2 +- .../StatusAndInfo/StatusAndInfoViewModel.cs | 2 +- .../Pages/StatusAndInfo/ToolTipViewModel.cs | 2 +- .../Pages/Text/AutoSuggestBoxViewModel.cs | 2 +- .../ViewModels/Pages/Text/LabelViewModel.cs | 2 +- .../Pages/Text/NumberBoxViewModel.cs | 2 +- .../Pages/Text/PasswordBoxViewModel.cs | 2 +- .../Pages/Text/RichTextBoxViewModel.cs | 2 +- .../Pages/Text/TextBlockViewModel.cs | 2 +- .../ViewModels/Pages/Text/TextBoxViewModel.cs | 2 +- .../ViewModels/Pages/Text/TextViewModel.cs | 4 +- .../Pages/Windows/WindowsViewModel.cs | 2 +- src/Wpf.Ui.Gallery/ViewModels/ViewModel.cs | 53 +++++++ .../Windows/EditorWindowViewModel.cs | 2 +- .../ViewModels/Windows/MainWindowViewModel.cs | 2 +- .../Windows/MonacoWindowViewModel.cs | 3 +- .../Windows/SandboxWindowViewModel.cs | 2 +- .../Views/Pages/AllControlsPage.xaml.cs | 1 - .../Wpf.Ui.SyntaxHighlight.csproj | 29 ++-- .../GlobalUsings.cs} | 4 +- .../Properties/AssemblyInfo.cs | 2 - src/Wpf.Ui.ToastNotifications/Toast.cs | 2 - .../Wpf.Ui.ToastNotifications.csproj | 53 +------ src/Wpf.Ui.Tray/Controls/NotifyIcon.cs | 2 - src/Wpf.Ui.Tray/GlobalUsings.cs | 12 ++ src/Wpf.Ui.Tray/Hicon.cs | 3 - src/Wpf.Ui.Tray/INotifyIcon.cs | 2 - .../Internal/InternalNotifyIconManager.cs | 9 +- src/Wpf.Ui.Tray/Interop/Shell32.cs | 2 - src/Wpf.Ui.Tray/Interop/User32.cs | 3 - src/Wpf.Ui.Tray/NotifyIconService.cs | 1 - src/Wpf.Ui.Tray/RoutedNotifyIconEvent.cs | 1 - src/Wpf.Ui.Tray/TrayData.cs | 2 - src/Wpf.Ui.Tray/TrayHandler.cs | 3 - src/Wpf.Ui.Tray/TrayManager.cs | 2 - src/Wpf.Ui.Tray/Wpf.Ui.Tray.csproj | 69 ++-------- .../ApplicationAccentColorManager.cs | 8 +- .../Appearance/ApplicationThemeManager.cs | 4 +- src/Wpf.Ui/Appearance/ObservedWindow.cs | 34 ++++- .../CardControlAutomationPeer.cs | 21 ++- .../NavigationView/INavigationView.cs | 1 + .../NavigationView.Navigation.cs | 2 + .../NavigationView/NavigationViewActivator.cs | 1 + .../NavigationViewContentPresenter.cs | 21 ++- .../VirtualizingWrapPanel.cs | 3 +- src/Wpf.Ui/{Usings.cs => GlobalUsings.cs} | 0 src/Wpf.Ui/INavigationService.cs | 1 + src/Wpf.Ui/INavigationWindow.cs | 1 + src/Wpf.Ui/IPageService.cs | 29 ---- src/Wpf.Ui/Interop/UnsafeNativeMethods.cs | 4 +- src/Wpf.Ui/Markup/Design.cs | 7 +- src/Wpf.Ui/NavigationService.cs | 1 + src/Wpf.Ui/UiApplication.cs | 17 ++- src/Wpf.Ui/Win32/Utilities.cs | 6 +- src/Wpf.Ui/Wpf.Ui.csproj | 84 ++--------- 194 files changed, 863 insertions(+), 649 deletions(-) create mode 100644 LICENSE.md create mode 100644 ThirdPartyNotices.txt rename src/Wpf.Ui.Demo.Mvvm/Assets/applicationIcon-1024.png => build/nuget.png (100%) rename src/Wpf.Ui.Demo.Console/Usings.cs => samples/Wpf.Ui.Demo.Console/GlobalUsings.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Models/DataColor.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Program.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Utilities/ThemeUtilities.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/MainView.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/MainView.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/Pages/DashboardPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/Pages/DashboardPage.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/Pages/DataPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/Pages/DataPage.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/Pages/SettingsPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/Pages/SettingsPage.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/SimpleView.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Views/SimpleView.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Console/Wpf.Ui.Demo.Console.csproj (65%) rename {src => samples}/Wpf.Ui.Demo.Console/wpfui.ico (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/App.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/App.xaml.cs (91%) create mode 100644 samples/Wpf.Ui.Demo.Mvvm/AssemblyInfo.cs rename {src/Wpf.Ui.Demo.Simple => samples/Wpf.Ui.Demo.Mvvm}/Assets/applicationIcon-1024.png (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Assets/applicationIcon-256.png (100%) create mode 100644 samples/Wpf.Ui.Demo.Mvvm/GlobalUsings.cs rename {src => samples}/Wpf.Ui.Demo.Mvvm/Helpers/EnumToBooleanConverter.cs (97%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Models/AppConfig.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Models/DataColor.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Services/ApplicationHostService.cs (79%) create mode 100644 samples/Wpf.Ui.Demo.Mvvm/Services/PageService.cs rename {src => samples}/Wpf.Ui.Demo.Mvvm/ViewModels/DashboardViewModel.cs (75%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/ViewModels/DataViewModel.cs (88%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/ViewModels/MainWindowViewModel.cs (97%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/ViewModels/SettingsViewModel.cs (92%) create mode 100644 samples/Wpf.Ui.Demo.Mvvm/ViewModels/ViewModel.cs rename {src => samples}/Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml.cs (98%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Views/Pages/DashboardPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Views/Pages/DashboardPage.xaml.cs (85%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Views/Pages/DataPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Views/Pages/DataPage.xaml.cs (85%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Views/Pages/SettingsPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Views/Pages/SettingsPage.xaml.cs (85%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj (57%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/app.manifest (100%) rename {src => samples}/Wpf.Ui.Demo.Mvvm/applicationIcon.ico (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/App.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/App.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/AssemblyInfo.cs (100%) create mode 100644 samples/Wpf.Ui.Demo.Simple/Assets/applicationIcon-1024.png rename {src => samples}/Wpf.Ui.Demo.Simple/Assets/applicationIcon-256.png (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/MainWindow.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/MainWindow.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/Models/DataColor.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/Views/Pages/DashboardPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/Views/Pages/DashboardPage.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/Views/Pages/DataPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/Views/Pages/DataPage.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/Views/Pages/SettingsPage.xaml (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/Views/Pages/SettingsPage.xaml.cs (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/Wpf.Ui.Demo.Simple.csproj (53%) rename {src => samples}/Wpf.Ui.Demo.Simple/app.manifest (100%) rename {src => samples}/Wpf.Ui.Demo.Simple/applicationIcon.ico (100%) rename src/{Wpf.Ui/Controls/NavigationView => Wpf.Ui.Abstractions/Controls}/INavigableView.cs (81%) rename src/{Wpf.Ui/Controls/NavigationView => Wpf.Ui.Abstractions/Controls}/INavigationAware.cs (50%) create mode 100644 src/Wpf.Ui.Abstractions/Controls/NavigationAware.cs create mode 100644 src/Wpf.Ui.Abstractions/GlobalUsings.cs create mode 100644 src/Wpf.Ui.Abstractions/IPageService.cs create mode 100644 src/Wpf.Ui.Abstractions/NavigationException.cs create mode 100644 src/Wpf.Ui.Abstractions/PageServiceExtensions.cs create mode 100644 src/Wpf.Ui.Abstractions/Wpf.Ui.Abstractions.csproj delete mode 100644 src/Wpf.Ui.Demo.Mvvm/AssemblyInfo.cs delete mode 100644 src/Wpf.Ui.Demo.Mvvm/Services/PageService.cs create mode 100644 src/Wpf.Ui.FontMapper/GlobalUsings.cs rename src/Wpf.Ui.Gallery/{Usings.cs => GlobalUsings.cs} (96%) create mode 100644 src/Wpf.Ui.Gallery/ViewModels/ViewModel.cs rename src/{Wpf.Ui.Demo.Mvvm/Usings.cs => Wpf.Ui.ToastNotifications/GlobalUsings.cs} (76%) create mode 100644 src/Wpf.Ui.Tray/GlobalUsings.cs rename src/Wpf.Ui/{Usings.cs => GlobalUsings.cs} (100%) delete mode 100644 src/Wpf.Ui/IPageService.cs diff --git a/.github/workflows/wpf-ui-cd-nuget.yaml b/.github/workflows/wpf-ui-cd-nuget.yaml index 9fd8c41e7..4c19d45ea 100644 --- a/.github/workflows/wpf-ui-cd-nuget.yaml +++ b/.github/workflows/wpf-ui-cd-nuget.yaml @@ -28,6 +28,9 @@ jobs: - name: Build run: dotnet build src\Wpf.Ui\Wpf.Ui.csproj --configuration Release --no-restore -p:SourceLinkEnabled=true + - name: Build + run: dotnet build src\Wpf.Ui.Abstractions\Wpf.Ui.Abstractions.csproj --configuration Release --no-restore -p:SourceLinkEnabled=true + - name: Build run: dotnet build src\Wpf.Ui.Tray\Wpf.Ui.Tray.csproj --configuration Release --no-restore -p:SourceLinkEnabled=true diff --git a/Directory.Build.props b/Directory.Build.props index c6aabc6b9..f41b3dcea 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,36 +1,28 @@ + - 3.0.4 - 12.0 - true + $(MSBuildThisFileDirectory) + $(RepositoryDirectory)build\ - net8.0-windows;net7.0-windows;net6.0-windows;net481;net472;net462 + 4.0.0-rc.1 - enable - enable - $(Version) - lepo.co lepo.co - Copyright (C) 2021-2024 Leszek Pomianowski and WPF UI Contributors - true + lepo.co + WPF-UI + lepoco;toolkit;wpf;fluent;navigation;controls;design;icons;system;accent;theme;winui MIT - https://raw.githubusercontent.com/lepoco/wpfui/main/LICENSE + true + Copyright (C) 2021-2024 Leszek Pomianowski and WPF UI Contributors https://github.com/lepoco/wpfui https://github.com/lepoco/wpfui/releases - https://github.com/lepoco/wpfui + Icon.png + https://github.com/lepoco/wpfui/main/build/nuget.png main git - WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly. - wpf ui wpfui fluent design winui windows controls custom metro modern xaml toolkit color dark theme lepo net6 net5 net - README.md - - - - true @@ -41,18 +33,32 @@ true - - - + + true + true + - - - + + true + 12.0 + enable + + + $(NoWarn);CS8500 + + + + $(MSBuildProjectName.Contains('Test')) + False + True + - - <_Parameter1>$(MSBuildProjectName).UnitTests - + diff --git a/Directory.Build.targets b/Directory.Build.targets index c9fb730d2..42b05531c 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,4 +1,103 @@ + + + true + + + + $(CommonTags);.NET + $(CommonTags);$(PackageTags) + $(CommonTags) + + + + true + README.md + false + true + snupkg + true + true + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + <_Parameter1>CommitHash + <_Parameter2>$(SourceRevisionId) + + + + + + + true + true + true + true + + + + + $(IntermediateOutputPath)$(MSBuildProjectName).SkipLocalsInit.g.cs + + +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +[module: global::System.Runtime.CompilerServices.SkipLocalsInitAttribute]]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PerMonitor + true/PM + true + + + + + + + + + + diff --git a/samples/Wpf.Ui.Demo.Dialogs/applicationIcon.ico b/samples/Wpf.Ui.Demo.Dialogs/applicationIcon.ico new file mode 100644 index 0000000000000000000000000000000000000000..cc128fda396328cd04b533b9b08b1c6db4988146 GIT binary patch literal 19438 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 N)4sJdOJ2@6@J}ZcNv8k+ literal 0 HcmV?d00001 diff --git a/samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs b/samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs index aec79ead2..a410c0324 100644 --- a/samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs +++ b/samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs @@ -3,10 +3,10 @@ // Copyright (C) Leszek Pomianowski and WPF UI Contributors. // All Rights Reserved. -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; using System.IO; using System.Windows.Threading; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Wpf.Ui.Abstractions; using Wpf.Ui.Demo.Mvvm.Models; using Wpf.Ui.Demo.Mvvm.Services; @@ -74,10 +74,7 @@ public partial class App /// public static IServiceProvider Services { - get - { - return _host.Services; - } + get { return _host.Services; } } /// diff --git a/src/Wpf.Ui.Gallery/GlobalUsings.cs b/src/Wpf.Ui.Gallery/GlobalUsings.cs index bd2892d75..c26fd1471 100644 --- a/src/Wpf.Ui.Gallery/GlobalUsings.cs +++ b/src/Wpf.Ui.Gallery/GlobalUsings.cs @@ -3,11 +3,6 @@ // Copyright (C) Leszek Pomianowski and WPF UI Contributors. // All Rights Reserved. -global using CommunityToolkit.Mvvm.ComponentModel; -global using CommunityToolkit.Mvvm.Input; -global using Microsoft.Extensions.Configuration; -global using Microsoft.Extensions.DependencyInjection; -global using Microsoft.Extensions.Hosting; global using System; global using System.Collections.Generic; global using System.Collections.ObjectModel; @@ -25,4 +20,9 @@ global using System.Windows.Markup; global using System.Windows.Media; global using System.Windows.Threading; -global using Wpf.Ui.Abstractions.Controls; \ No newline at end of file +global using CommunityToolkit.Mvvm.ComponentModel; +global using CommunityToolkit.Mvvm.Input; +global using Microsoft.Extensions.Configuration; +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Hosting; +global using Wpf.Ui.Abstractions.Controls; From b13221e6a920df43b28b9e05571a265a37a34d72 Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Mon, 3 Jun 2024 00:43:23 +0200 Subject: [PATCH 07/13] Simplify demo --- samples/Wpf.Ui.Demo.Dialogs/App.xaml | 13 +------------ samples/Wpf.Ui.Demo.Dialogs/MainWindow.xaml | 9 ++++++++- src/Wpf.Ui/Controls/ContentDialog/ContentDialog.cs | 1 + 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/samples/Wpf.Ui.Demo.Dialogs/App.xaml b/samples/Wpf.Ui.Demo.Dialogs/App.xaml index e88ef75aa..6caa7edc6 100644 --- a/samples/Wpf.Ui.Demo.Dialogs/App.xaml +++ b/samples/Wpf.Ui.Demo.Dialogs/App.xaml @@ -2,15 +2,4 @@ x:Class="Wpf.Ui.Demo.Dialogs.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="clr-namespace:Wpf.Ui.Demo.Dialogs" - xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" - StartupUri="MainWindow.xaml"> - - - - - - - - - + StartupUri="MainWindow.xaml" /> diff --git a/samples/Wpf.Ui.Demo.Dialogs/MainWindow.xaml b/samples/Wpf.Ui.Demo.Dialogs/MainWindow.xaml index 31cac7ff5..7e6c222d6 100644 --- a/samples/Wpf.Ui.Demo.Dialogs/MainWindow.xaml +++ b/samples/Wpf.Ui.Demo.Dialogs/MainWindow.xaml @@ -3,13 +3,20 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:Wpf.Ui.Demo.Dialogs" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" Title="WPF UI - Dialog sample" Width="800" Height="450" mc:Ignorable="d"> + + + + + + + + Date: Sun, 9 Jun 2024 13:47:30 +0200 Subject: [PATCH 08/13] Test translations --- Directory.Packages.props | 11 ++- src/Wpf.Ui.Gallery/App.xaml.cs | 7 ++ .../ControlsLookup/GalleryPageAttribute.cs | 12 +-- src/Wpf.Ui.Gallery/Resources/Translations.cs | 8 ++ .../Resources/Translations.pl-PL.Designer.cs | 80 +++++++++++++++++++ .../Resources/Translations.pl-PL.resx | 27 +++++++ .../ViewModels/Windows/MainWindowViewModel.cs | 6 +- .../Views/Windows/MainWindow.xaml | 3 +- src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj | 17 ++++ 9 files changed, 155 insertions(+), 16 deletions(-) create mode 100644 src/Wpf.Ui.Gallery/Resources/Translations.cs create mode 100644 src/Wpf.Ui.Gallery/Resources/Translations.pl-PL.Designer.cs create mode 100644 src/Wpf.Ui.Gallery/Resources/Translations.pl-PL.resx diff --git a/Directory.Packages.props b/Directory.Packages.props index 4d31ec245..3d358a5f3 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,14 +2,17 @@ - + + + + - + - + @@ -21,4 +24,4 @@ - + \ No newline at end of file diff --git a/src/Wpf.Ui.Gallery/App.xaml.cs b/src/Wpf.Ui.Gallery/App.xaml.cs index 9022a6ff5..62de524a5 100644 --- a/src/Wpf.Ui.Gallery/App.xaml.cs +++ b/src/Wpf.Ui.Gallery/App.xaml.cs @@ -3,7 +3,9 @@ // Copyright (C) Leszek Pomianowski and WPF UI Contributors. // All Rights Reserved. +using Lepo.i18n.DependencyInjection; using Wpf.Ui.Gallery.DependencyModel; +using Wpf.Ui.Gallery.Resources; using Wpf.Ui.Gallery.Services; using Wpf.Ui.Gallery.Services.Contracts; using Wpf.Ui.Gallery.ViewModels.Pages; @@ -53,6 +55,11 @@ public partial class App "Wpf.Ui.Gallery.ViewModels", GalleryAssembly.Asssembly ); + + _ = services.AddStringLocalizer(b => + { + b.FromResource(new("pl-PL")); + }); } ) .Build(); diff --git a/src/Wpf.Ui.Gallery/ControlsLookup/GalleryPageAttribute.cs b/src/Wpf.Ui.Gallery/ControlsLookup/GalleryPageAttribute.cs index a201ca741..e1596b0c6 100644 --- a/src/Wpf.Ui.Gallery/ControlsLookup/GalleryPageAttribute.cs +++ b/src/Wpf.Ui.Gallery/ControlsLookup/GalleryPageAttribute.cs @@ -8,15 +8,9 @@ namespace Wpf.Ui.Gallery.ControlsLookup; [AttributeUsage(AttributeTargets.Class)] -internal class GalleryPageAttribute : Attribute +internal sealed class GalleryPageAttribute(string description, SymbolRegular icon) : Attribute { - public string Description { get; } + public string Description { get; } = description; - public SymbolRegular Icon { get; } - - public GalleryPageAttribute(string description, SymbolRegular icon) - { - Description = description; - Icon = icon; - } + public SymbolRegular Icon { get; } = icon; } diff --git a/src/Wpf.Ui.Gallery/Resources/Translations.cs b/src/Wpf.Ui.Gallery/Resources/Translations.cs new file mode 100644 index 000000000..2fd340047 --- /dev/null +++ b/src/Wpf.Ui.Gallery/Resources/Translations.cs @@ -0,0 +1,8 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +namespace Wpf.Ui.Gallery.Resources; + +public partial class Translations; \ No newline at end of file diff --git a/src/Wpf.Ui.Gallery/Resources/Translations.pl-PL.Designer.cs b/src/Wpf.Ui.Gallery/Resources/Translations.pl-PL.Designer.cs new file mode 100644 index 000000000..4c5543244 --- /dev/null +++ b/src/Wpf.Ui.Gallery/Resources/Translations.pl-PL.Designer.cs @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Wpf.Ui.Gallery.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Translations_pl_PL { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Translations_pl_PL() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Wpf.Ui.Gallery.Resources.Translations.pl-PL", typeof(Translations_pl_PL).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Szukaj. + /// + internal static string Search { + get { + return ResourceManager.GetString("Search", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to WPF UI Galeria. + /// + internal static string WPF_UI_Gallery { + get { + return ResourceManager.GetString("WPF UI Gallery", resourceCulture); + } + } + } +} diff --git a/src/Wpf.Ui.Gallery/Resources/Translations.pl-PL.resx b/src/Wpf.Ui.Gallery/Resources/Translations.pl-PL.resx new file mode 100644 index 000000000..f24f175a5 --- /dev/null +++ b/src/Wpf.Ui.Gallery/Resources/Translations.pl-PL.resx @@ -0,0 +1,27 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Szukaj + + + WPF UI Galeria + + \ No newline at end of file diff --git a/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs index f7e3cd8c7..c6101117e 100644 --- a/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs +++ b/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs @@ -5,7 +5,9 @@ using System.Windows.Controls; using System.Windows.Controls.Primitives; +using Microsoft.Extensions.Localization; using Wpf.Ui.Controls; +using Wpf.Ui.Gallery.Resources; using Wpf.Ui.Gallery.Views.Pages; using Wpf.Ui.Gallery.Views.Pages.BasicInput; using Wpf.Ui.Gallery.Views.Pages.Collections; @@ -22,10 +24,10 @@ namespace Wpf.Ui.Gallery.ViewModels.Windows; -public partial class MainWindowViewModel : ViewModel +public partial class MainWindowViewModel(IStringLocalizer localizer) : ViewModel { [ObservableProperty] - private string _applicationTitle = "WPF UI Gallery"; + private string _applicationTitle = localizer["WPF UI Gallery"]; [ObservableProperty] private ObservableCollection _menuItems = diff --git a/src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml b/src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml index 8bdf9a37a..a6a9607a2 100644 --- a/src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml +++ b/src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml @@ -4,6 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:Wpf.Ui.Gallery.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:i18n="http://schemas.lepo.co/i18n/2022/xaml" xmlns:local="clr-namespace:Wpf.Ui.Gallery.Views.Windows" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:tray="http://schemas.lepo.co/wpfui/2022/xaml/tray" @@ -57,7 +58,7 @@ - + diff --git a/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj b/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj index b26fcc916..7969d2597 100644 --- a/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj +++ b/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj @@ -17,6 +17,8 @@ + + @@ -72,4 +74,19 @@ + + + ResXFileCodeGenerator + Translations.pl-PL.Designer.cs + + + + + + True + True + Translations.pl-PL.resx + + + From e8a9185ffcc87eb636903b3cb87465a09fb7c534 Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Tue, 11 Jun 2024 02:05:14 +0200 Subject: [PATCH 09/13] Update interfaces --- src/Wpf.Ui.Gallery/App.xaml.cs | 6 +++--- src/Wpf.Ui.Gallery/Resources/Translations.cs | 2 +- .../NavigationViewContentPresenter.cs | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Wpf.Ui.Gallery/App.xaml.cs b/src/Wpf.Ui.Gallery/App.xaml.cs index 62de524a5..253677628 100644 --- a/src/Wpf.Ui.Gallery/App.xaml.cs +++ b/src/Wpf.Ui.Gallery/App.xaml.cs @@ -57,9 +57,9 @@ public partial class App ); _ = services.AddStringLocalizer(b => - { - b.FromResource(new("pl-PL")); - }); + { + b.FromResource(new("pl-PL")); + }); } ) .Build(); diff --git a/src/Wpf.Ui.Gallery/Resources/Translations.cs b/src/Wpf.Ui.Gallery/Resources/Translations.cs index 2fd340047..273c6012d 100644 --- a/src/Wpf.Ui.Gallery/Resources/Translations.cs +++ b/src/Wpf.Ui.Gallery/Resources/Translations.cs @@ -5,4 +5,4 @@ namespace Wpf.Ui.Gallery.Resources; -public partial class Translations; \ No newline at end of file +public partial class Translations; diff --git a/src/Wpf.Ui/Controls/NavigationView/NavigationViewContentPresenter.cs b/src/Wpf.Ui/Controls/NavigationView/NavigationViewContentPresenter.cs index b1bbe2cf4..a0a3a34e8 100644 --- a/src/Wpf.Ui/Controls/NavigationView/NavigationViewContentPresenter.cs +++ b/src/Wpf.Ui/Controls/NavigationView/NavigationViewContentPresenter.cs @@ -8,6 +8,7 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Navigation; +using Wpf.Ui.Abstractions.Controls; using Wpf.Ui.Animations; // ReSharper disable once CheckNamespace @@ -186,13 +187,13 @@ private static void NotifyContentAboutNavigatingTo(object content) switch (content) { case INavigationAware navigationAwareNavigationContent: - navigationAwareNavigationContent.OnNavigatedTo(); + _ = Task.Run(navigationAwareNavigationContent.OnNavigatedToAsync).ConfigureAwait(false); break; case INavigableView { ViewModel: INavigationAware navigationAwareNavigableViewViewModel }: - navigationAwareNavigableViewViewModel.OnNavigatedTo(); + _ = Task.Run(navigationAwareNavigableViewViewModel.OnNavigatedToAsync).ConfigureAwait(false); break; case FrameworkElement { DataContext: INavigationAware navigationAwareCurrentContent }: - navigationAwareCurrentContent.OnNavigatedTo(); + _ = Task.Run(navigationAwareCurrentContent.OnNavigatedToAsync).ConfigureAwait(false); break; } } @@ -202,13 +203,14 @@ private static void NotifyContentAboutNavigatingFrom(object content) switch (content) { case INavigationAware navigationAwareNavigationContent: - navigationAwareNavigationContent.OnNavigatedFrom(); + _ = Task.Run(navigationAwareNavigationContent.OnNavigatedFromAsync).ConfigureAwait(false); break; case INavigableView { ViewModel: INavigationAware navigationAwareNavigableViewViewModel }: - navigationAwareNavigableViewViewModel.OnNavigatedFrom(); + _ = Task.Run(navigationAwareNavigableViewViewModel.OnNavigatedFromAsync) + .ConfigureAwait(false); break; case FrameworkElement { DataContext: INavigationAware navigationAwareCurrentContent }: - navigationAwareCurrentContent.OnNavigatedFrom(); + _ = Task.Run(navigationAwareCurrentContent.OnNavigatedFromAsync).ConfigureAwait(false); break; } } From ab9d02409e5a8ed644eb9222af31af86707a9ee0 Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:46:11 +0200 Subject: [PATCH 10/13] Provide default navigation page provider #1134 --- Directory.Packages.props | 1 + Wpf.Ui.sln | 20 ++++++- samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs | 7 ++- .../Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml.cs | 7 +-- .../Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj | 1 + ...vice.cs => INavigationViewPageProvider.cs} | 2 +- ...> NavigationViewPageProviderExtensions.cs} | 16 +++--- ...encyInjectionNavigationViewPageProvider.cs | 10 ++-- .../GlobalUsings.cs | 6 +++ .../ServiceCollectionExtensions.cs | 31 +++++++++++ .../Wpf.Ui.DependencyInjection.csproj | 27 ++++++++++ src/Wpf.Ui.Gallery/App.xaml.cs | 3 ++ .../Views/Windows/MainWindow.xaml.cs | 2 - src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj | 1 + src/Wpf.Ui/Controls/ComboBox/ComboBox.xaml | 4 +- .../Controls/ContextMenu/ContextMenu.xaml | 4 +- .../Controls/ListView/ListViewItem.xaml | 2 +- src/Wpf.Ui/Controls/Menu/MenuItem.xaml | 28 +++++----- .../NavigationView/INavigationView.cs | 2 +- .../NavigationView.Navigation.cs | 9 ++-- .../NavigationView/NavigationViewActivator.cs | 4 +- src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml | 4 +- src/Wpf.Ui/INavigationService.cs | 16 ++---- src/Wpf.Ui/INavigationWindow.cs | 8 +-- src/Wpf.Ui/NavigationService.cs | 54 +------------------ .../DefaultTextBoxScrollViewerStyle.xaml | 3 +- 26 files changed, 149 insertions(+), 123 deletions(-) rename src/Wpf.Ui.Abstractions/{IPageService.cs => INavigationViewPageProvider.cs} (93%) rename src/Wpf.Ui.Abstractions/{PageServiceExtensions.cs => NavigationViewPageProviderExtensions.cs} (64%) rename samples/Wpf.Ui.Demo.Mvvm/Services/PageService.cs => src/Wpf.Ui.DependencyInjection/DependencyInjectionNavigationViewPageProvider.cs (64%) create mode 100644 src/Wpf.Ui.DependencyInjection/GlobalUsings.cs create mode 100644 src/Wpf.Ui.DependencyInjection/ServiceCollectionExtensions.cs create mode 100644 src/Wpf.Ui.DependencyInjection/Wpf.Ui.DependencyInjection.csproj diff --git a/Directory.Packages.props b/Directory.Packages.props index 3d358a5f3..2a1de267d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,6 +6,7 @@ + diff --git a/Wpf.Ui.sln b/Wpf.Ui.sln index 0bb3f90dc..03c890493 100644 --- a/Wpf.Ui.sln +++ b/Wpf.Ui.sln @@ -55,7 +55,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wpf.Ui.Demo.Mvvm", "samples EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wpf.Ui.Demo.Simple", "samples\Wpf.Ui.Demo.Simple\Wpf.Ui.Demo.Simple.csproj", "{E37CD05A-EBFC-429D-A550-BEE44119FA9E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wpf.Ui.Demo.Dialogs", "samples\Wpf.Ui.Demo.Dialogs\Wpf.Ui.Demo.Dialogs.csproj", "{7F6C7E7A-A4B5-4D12-88EB-217CA59284F4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wpf.Ui.Demo.Dialogs", "samples\Wpf.Ui.Demo.Dialogs\Wpf.Ui.Demo.Dialogs.csproj", "{7F6C7E7A-A4B5-4D12-88EB-217CA59284F4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wpf.Ui.DependencyInjection", "src\Wpf.Ui.DependencyInjection\Wpf.Ui.DependencyInjection.csproj", "{9C8D6133-9417-43A1-B54F-725009569D71}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -359,6 +361,22 @@ Global {7F6C7E7A-A4B5-4D12-88EB-217CA59284F4}.Release|x64.Build.0 = Release|Any CPU {7F6C7E7A-A4B5-4D12-88EB-217CA59284F4}.Release|x86.ActiveCfg = Release|Any CPU {7F6C7E7A-A4B5-4D12-88EB-217CA59284F4}.Release|x86.Build.0 = Release|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Debug|arm64.ActiveCfg = Debug|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Debug|arm64.Build.0 = Debug|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Debug|x64.ActiveCfg = Debug|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Debug|x64.Build.0 = Debug|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Debug|x86.ActiveCfg = Debug|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Debug|x86.Build.0 = Debug|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Release|Any CPU.Build.0 = Release|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Release|arm64.ActiveCfg = Release|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Release|arm64.Build.0 = Release|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Release|x64.ActiveCfg = Release|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Release|x64.Build.0 = Release|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Release|x86.ActiveCfg = Release|Any CPU + {9C8D6133-9417-43A1-B54F-725009569D71}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs b/samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs index a410c0324..652455eca 100644 --- a/samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs +++ b/samples/Wpf.Ui.Demo.Mvvm/App.xaml.cs @@ -7,9 +7,9 @@ using System.Windows.Threading; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Wpf.Ui.Abstractions; using Wpf.Ui.Demo.Mvvm.Models; using Wpf.Ui.Demo.Mvvm.Services; +using Wpf.Ui.DependencyInjection; namespace Wpf.Ui.Demo.Mvvm; @@ -36,12 +36,11 @@ public partial class App .ConfigureServices( (context, services) => { + _ = services.AddNavigationViewPageProvider(); + // App Host _ = services.AddHostedService(); - // Page resolver service - _ = services.AddSingleton(); - // Theme manipulation _ = services.AddSingleton(); diff --git a/samples/Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml.cs b/samples/Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml.cs index cb2504eac..ccec9dada 100644 --- a/samples/Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml.cs +++ b/samples/Wpf.Ui.Demo.Mvvm/Views/MainWindow.xaml.cs @@ -17,7 +17,7 @@ public partial class MainWindow : INavigationWindow public MainWindow( ViewModels.MainWindowViewModel viewModel, - IPageService pageService, + INavigationViewPageProvider navigationViewPageProvider, INavigationService navigationService ) { @@ -27,7 +27,7 @@ INavigationService navigationService Appearance.SystemThemeWatcher.Watch(this); InitializeComponent(); - SetPageService(pageService); + SetPageService(navigationViewPageProvider); navigationService.SetNavigationControl(RootNavigation); } @@ -36,7 +36,8 @@ 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(); diff --git a/samples/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj b/samples/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj index 2318d702c..7e24cbdd1 100644 --- a/samples/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj +++ b/samples/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj @@ -26,6 +26,7 @@ + diff --git a/src/Wpf.Ui.Abstractions/IPageService.cs b/src/Wpf.Ui.Abstractions/INavigationViewPageProvider.cs similarity index 93% rename from src/Wpf.Ui.Abstractions/IPageService.cs rename to src/Wpf.Ui.Abstractions/INavigationViewPageProvider.cs index 54fa6dd7f..d983f743b 100644 --- a/src/Wpf.Ui.Abstractions/IPageService.cs +++ b/src/Wpf.Ui.Abstractions/INavigationViewPageProvider.cs @@ -8,7 +8,7 @@ namespace Wpf.Ui.Abstractions; /// /// Defines a service that provides pages for navigation. /// -public interface IPageService +public interface INavigationViewPageProvider { /// /// Retrieves a page of the specified type. diff --git a/src/Wpf.Ui.Abstractions/PageServiceExtensions.cs b/src/Wpf.Ui.Abstractions/NavigationViewPageProviderExtensions.cs similarity index 64% rename from src/Wpf.Ui.Abstractions/PageServiceExtensions.cs rename to src/Wpf.Ui.Abstractions/NavigationViewPageProviderExtensions.cs index ca4ab5398..a5d4554d8 100644 --- a/src/Wpf.Ui.Abstractions/PageServiceExtensions.cs +++ b/src/Wpf.Ui.Abstractions/NavigationViewPageProviderExtensions.cs @@ -6,20 +6,20 @@ namespace Wpf.Ui.Abstractions; /// -/// Provides extension methods for the IPageService interface. +/// Provides extension methods for the INavigationViewPageProvider interface. /// -public static class PageServiceExtensions +public static class NavigationViewPageProviderExtensions { /// /// Retrieves a page of the specified type from the page service. /// /// The type of the page to retrieve. - /// The page service instance. + /// The page service instance. /// An instance of the specified page type, or null if the page is not found. - public static TPage? GetPage(this IPageService pageService) + public static TPage? GetPage(this INavigationViewPageProvider navigationViewPageProvider) where TPage : class { - return pageService.GetPage(typeof(TPage)) as TPage; + return navigationViewPageProvider.GetPage(typeof(TPage)) as TPage; } /// @@ -27,13 +27,13 @@ public static class PageServiceExtensions /// Throws a NavigationException if the page is not found. /// /// The type of the page to retrieve. - /// The page service instance. + /// The page service instance. /// An instance of the specified page type. /// Thrown when the specified page type is not found. - public static TPage GetRequiredPage(this IPageService pageService) + public static TPage GetRequiredPage(this INavigationViewPageProvider navigationViewPageProvider) where TPage : class { - return pageService.GetPage(typeof(TPage)) as TPage + return navigationViewPageProvider.GetPage(typeof(TPage)) as TPage ?? throw new NavigationException($"{typeof(TPage)} page not found."); } } diff --git a/samples/Wpf.Ui.Demo.Mvvm/Services/PageService.cs b/src/Wpf.Ui.DependencyInjection/DependencyInjectionNavigationViewPageProvider.cs similarity index 64% rename from samples/Wpf.Ui.Demo.Mvvm/Services/PageService.cs rename to src/Wpf.Ui.DependencyInjection/DependencyInjectionNavigationViewPageProvider.cs index e5feb8d43..de5ef1927 100644 --- a/samples/Wpf.Ui.Demo.Mvvm/Services/PageService.cs +++ b/src/Wpf.Ui.DependencyInjection/DependencyInjectionNavigationViewPageProvider.cs @@ -5,21 +5,17 @@ using Wpf.Ui.Abstractions; -namespace Wpf.Ui.Demo.Mvvm.Services; +namespace Wpf.Ui.DependencyInjection; /// /// Service that provides pages for navigation. /// -public class PageService(IServiceProvider serviceProvider) : IPageService +public class DependencyInjectionNavigationViewPageProvider(IServiceProvider serviceProvider) + : INavigationViewPageProvider { /// public object? GetPage(Type pageType) { - if (!typeof(FrameworkElement).IsAssignableFrom(pageType)) - { - throw new InvalidOperationException("The page should be a WPF control."); - } - return serviceProvider.GetService(pageType); } } diff --git a/src/Wpf.Ui.DependencyInjection/GlobalUsings.cs b/src/Wpf.Ui.DependencyInjection/GlobalUsings.cs new file mode 100644 index 000000000..bc3b69a4d --- /dev/null +++ b/src/Wpf.Ui.DependencyInjection/GlobalUsings.cs @@ -0,0 +1,6 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +global using System; diff --git a/src/Wpf.Ui.DependencyInjection/ServiceCollectionExtensions.cs b/src/Wpf.Ui.DependencyInjection/ServiceCollectionExtensions.cs new file mode 100644 index 000000000..71a7be708 --- /dev/null +++ b/src/Wpf.Ui.DependencyInjection/ServiceCollectionExtensions.cs @@ -0,0 +1,31 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +using Microsoft.Extensions.DependencyInjection; +using Wpf.Ui.Abstractions; + +namespace Wpf.Ui.DependencyInjection; + +/// +/// Provides extension methods for to support WPF UI navigation and services. +/// +public static class ServiceCollectionExtensions +{ + /// + /// Adds the services necessary for page navigation within a WPF UI NavigationView. + /// + /// The to add the services to. + /// The so that additional calls can be chained. + + public static IServiceCollection AddNavigationViewPageProvider(this IServiceCollection services) + { + _ = services.AddSingleton< + INavigationViewPageProvider, + DependencyInjectionNavigationViewPageProvider + >(); + + return services; + } +} diff --git a/src/Wpf.Ui.DependencyInjection/Wpf.Ui.DependencyInjection.csproj b/src/Wpf.Ui.DependencyInjection/Wpf.Ui.DependencyInjection.csproj new file mode 100644 index 000000000..77003a0ac --- /dev/null +++ b/src/Wpf.Ui.DependencyInjection/Wpf.Ui.DependencyInjection.csproj @@ -0,0 +1,27 @@ + + + + WPF-UI.DependencyInjection + netstandard2.0;netstandard2.1;net462;net6.0;net8.0 + true + Dependency injection for the WPF UI. + $(CommonTags);dependency;injection;abstractions;standard + + + + + + all + build; analyzers + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + \ No newline at end of file diff --git a/src/Wpf.Ui.Gallery/App.xaml.cs b/src/Wpf.Ui.Gallery/App.xaml.cs index 253677628..6ded57e72 100644 --- a/src/Wpf.Ui.Gallery/App.xaml.cs +++ b/src/Wpf.Ui.Gallery/App.xaml.cs @@ -4,6 +4,7 @@ // All Rights Reserved. using Lepo.i18n.DependencyInjection; +using Wpf.Ui.DependencyInjection; using Wpf.Ui.Gallery.DependencyModel; using Wpf.Ui.Gallery.Resources; using Wpf.Ui.Gallery.Services; @@ -30,6 +31,8 @@ public partial class App .ConfigureServices( (_1, services) => { + _ = services.AddNavigationViewPageProvider(); + // App Host _ = services.AddHostedService(); diff --git a/src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml.cs b/src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml.cs index fc4e444df..cf2543f77 100644 --- a/src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml.cs +++ b/src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml.cs @@ -30,8 +30,6 @@ IContentDialogService contentDialogService snackbarService.SetSnackbarPresenter(SnackbarPresenter); navigationService.SetNavigationControl(NavigationView); contentDialogService.SetDialogHost(RootContentDialog); - - NavigationView.SetServiceProvider(serviceProvider); } public MainWindowViewModel ViewModel { get; } diff --git a/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj b/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj index 7969d2597..4dc4fc98d 100644 --- a/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj +++ b/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj @@ -26,6 +26,7 @@ + diff --git a/src/Wpf.Ui/Controls/ComboBox/ComboBox.xaml b/src/Wpf.Ui/Controls/ComboBox/ComboBox.xaml index c33cebc9b..1eb250459 100644 --- a/src/Wpf.Ui/Controls/ComboBox/ComboBox.xaml +++ b/src/Wpf.Ui/Controls/ComboBox/ComboBox.xaml @@ -46,9 +46,9 @@ diff --git a/src/Wpf.Ui/Controls/ContextMenu/ContextMenu.xaml b/src/Wpf.Ui/Controls/ContextMenu/ContextMenu.xaml index d627afdcb..c6c338051 100644 --- a/src/Wpf.Ui/Controls/ContextMenu/ContextMenu.xaml +++ b/src/Wpf.Ui/Controls/ContextMenu/ContextMenu.xaml @@ -5,9 +5,7 @@ All Rights Reserved. --> - +