From 780ee4ca0453f32e2e964758066bb56bc8580962 Mon Sep 17 00:00:00 2001 From: Nice3point Date: Tue, 4 Jul 2023 18:54:27 +0300 Subject: [PATCH 01/12] Remove non-writable properties --- src/Wpf.Ui/Styles/Controls/VirtualizingWrapPanel.xaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Wpf.Ui/Styles/Controls/VirtualizingWrapPanel.xaml b/src/Wpf.Ui/Styles/Controls/VirtualizingWrapPanel.xaml index ba601b0ee..f1bc66b55 100644 --- a/src/Wpf.Ui/Styles/Controls/VirtualizingWrapPanel.xaml +++ b/src/Wpf.Ui/Styles/Controls/VirtualizingWrapPanel.xaml @@ -15,8 +15,6 @@ - - From 9272e3b25bf2add44328ae2aed671accf8e4eccc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Nov 2023 23:59:07 +0000 Subject: [PATCH 02/12] Bump dessant/lock-threads from 4 to 5 Bumps [dessant/lock-threads](https://github.com/dessant/lock-threads) from 4 to 5. - [Release notes](https://github.com/dessant/lock-threads/releases) - [Changelog](https://github.com/dessant/lock-threads/blob/main/CHANGELOG.md) - [Commits](https://github.com/dessant/lock-threads/compare/v4...v5) --- updated-dependencies: - dependency-name: dessant/lock-threads dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/wpf-ui-lock.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wpf-ui-lock.yml b/.github/workflows/wpf-ui-lock.yml index 18a3a1f72..7914cce8f 100644 --- a/.github/workflows/wpf-ui-lock.yml +++ b/.github/workflows/wpf-ui-lock.yml @@ -8,7 +8,7 @@ jobs: lock: runs-on: ubuntu-latest steps: - - uses: dessant/lock-threads@v4 + - uses: dessant/lock-threads@v5 with: # https://github.com/dessant/lock-threads github-token: ${{ github.token }} From ad67f094523667d4b53af6a4e77f77ed23a729f1 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 15 Nov 2023 16:33:29 +0100 Subject: [PATCH 03/12] Updating ApplicationBackgroundColor --- src/Wpf.Ui/Resources/Theme/HC1.xaml | 2 +- src/Wpf.Ui/Resources/Theme/HC2.xaml | 2 +- src/Wpf.Ui/Resources/Theme/HCBlack.xaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Wpf.Ui/Resources/Theme/HC1.xaml b/src/Wpf.Ui/Resources/Theme/HC1.xaml index 32244999b..e49d98e8c 100644 --- a/src/Wpf.Ui/Resources/Theme/HC1.xaml +++ b/src/Wpf.Ui/Resources/Theme/HC1.xaml @@ -32,7 +32,7 @@ #A6A6A6 - #FFFAEF + #2D3236 diff --git a/src/Wpf.Ui/Resources/Theme/HC2.xaml b/src/Wpf.Ui/Resources/Theme/HC2.xaml index 18ebade4b..48d2cf1e9 100644 --- a/src/Wpf.Ui/Resources/Theme/HC2.xaml +++ b/src/Wpf.Ui/Resources/Theme/HC2.xaml @@ -31,7 +31,7 @@ #8080FF #A6A6A6 - #FFFAEF + #000000 diff --git a/src/Wpf.Ui/Resources/Theme/HCBlack.xaml b/src/Wpf.Ui/Resources/Theme/HCBlack.xaml index 8cd3859ba..c75cb3c72 100644 --- a/src/Wpf.Ui/Resources/Theme/HCBlack.xaml +++ b/src/Wpf.Ui/Resources/Theme/HCBlack.xaml @@ -31,7 +31,7 @@ #75E9FC #A6A6A6 - #FFFAEF + #202020 From 9bcd1ca1dcfdfa987600e6a06af729387309c225 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 17 Nov 2023 13:23:18 +0300 Subject: [PATCH 04/12] Replacing FontSize property (#824) --- src/Wpf.Ui/Controls/TextBlock/TextBlock.cs | 7 ------- src/Wpf.Ui/Controls/TextBlock/TextBlock.xaml | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Wpf.Ui/Controls/TextBlock/TextBlock.cs b/src/Wpf.Ui/Controls/TextBlock/TextBlock.cs index 5cef3edc7..86c6a2fd0 100644 --- a/src/Wpf.Ui/Controls/TextBlock/TextBlock.cs +++ b/src/Wpf.Ui/Controls/TextBlock/TextBlock.cs @@ -14,13 +14,6 @@ namespace Wpf.Ui.Controls; /// public class TextBlock : System.Windows.Controls.TextBlock { - static TextBlock() - { - TextElement - .FontSizeProperty - .OverrideMetadata(typeof(System.Windows.Controls.TextBlock), new FrameworkPropertyMetadata(14.0)); - } - /// /// Property for . /// diff --git a/src/Wpf.Ui/Controls/TextBlock/TextBlock.xaml b/src/Wpf.Ui/Controls/TextBlock/TextBlock.xaml index 8493f372d..b655bdf11 100644 --- a/src/Wpf.Ui/Controls/TextBlock/TextBlock.xaml +++ b/src/Wpf.Ui/Controls/TextBlock/TextBlock.xaml @@ -14,6 +14,7 @@ + From e7b16256636b1f5b4f8e4f919641a97183fe5924 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 22 Nov 2023 16:29:26 +0100 Subject: [PATCH 05/12] Formatting (#833) --- src/Wpf.Ui/Appearance/WindowBackgroundManager.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Wpf.Ui/Appearance/WindowBackgroundManager.cs b/src/Wpf.Ui/Appearance/WindowBackgroundManager.cs index fba0fa750..67c7d9207 100644 --- a/src/Wpf.Ui/Appearance/WindowBackgroundManager.cs +++ b/src/Wpf.Ui/Appearance/WindowBackgroundManager.cs @@ -70,11 +70,12 @@ bool forceBackground { backdrop = WindowBackdropType.None; } - else - { - _ = WindowBackdrop.RemoveBackground(window); - } + // This was required to update the background when moving from a HC theme to light/dark theme. However, this breaks theme proper light/dark theme changing on Windows 10. + // else + // { + // _ = WindowBackdrop.RemoveBackground(window); + // } _ = WindowBackdrop.ApplyBackdrop(window, backdrop); if (applicationTheme is ApplicationTheme.Dark) { From df28ac0d2f24947fb2f097f65b4da60246f721e3 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 22 Nov 2023 18:29:45 +0300 Subject: [PATCH 06/12] ContentDialog restore height resize (#828) --- src/Wpf.Ui/Controls/ContentDialog/ContentDialog.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Wpf.Ui/Controls/ContentDialog/ContentDialog.cs b/src/Wpf.Ui/Controls/ContentDialog/ContentDialog.cs index 6d5e325df..0b4117c0c 100644 --- a/src/Wpf.Ui/Controls/ContentDialog/ContentDialog.cs +++ b/src/Wpf.Ui/Controls/ContentDialog/ContentDialog.cs @@ -677,12 +677,13 @@ protected virtual void OnLoaded() private Size GetNewDialogSize(Size desiredSize) { var paddingWidth = Padding.Left + Padding.Right; + var paddingHeight = Padding.Top + Padding.Bottom; var marginHeight = DialogMargin.Bottom + DialogMargin.Top; var marginWidth = DialogMargin.Left + DialogMargin.Right; var width = desiredSize.Width - marginWidth + paddingWidth; - var height = desiredSize.Height - marginHeight; + var height = desiredSize.Height - marginHeight + paddingHeight; return new Size(width, height); } From ecf7c00026a6470987d429e5d42aca40c84cbaf5 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 22 Nov 2023 18:30:05 +0300 Subject: [PATCH 07/12] SymbolIconExtension converter (#827) --- src/Wpf.Ui/Markup/SymbolIconExtension.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Wpf.Ui/Markup/SymbolIconExtension.cs b/src/Wpf.Ui/Markup/SymbolIconExtension.cs index 1cc719f43..90ae2ea86 100644 --- a/src/Wpf.Ui/Markup/SymbolIconExtension.cs +++ b/src/Wpf.Ui/Markup/SymbolIconExtension.cs @@ -37,6 +37,11 @@ public SymbolIconExtension(SymbolRegular symbol) Symbol = symbol; } + public SymbolIconExtension(string symbol) + { + Symbol = (SymbolRegular)Enum.Parse(typeof(SymbolRegular), symbol); + } + public SymbolIconExtension(SymbolRegular symbol, bool filled) : this(symbol) { From f846a0f6cae9e951e7d626ffe21bbb3bb8ff275c Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:32:06 +0100 Subject: [PATCH 08/12] Update to .NET 8 --- Directory.Build.props | 6 ++--- Directory.Packages.props | 24 +++++++++---------- src/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj | 2 +- .../Wpf.Ui.Demo.Simple.csproj | 2 +- .../Wpf.Ui.FontMapper.csproj | 2 +- src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj | 2 +- .../Wpf.Ui.Gallery.UnitTests.csproj | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index c031cf77e..4657315c7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,8 @@ - 3.0.0-preview.9 - 11.0 + 3.0.0-preview.10 + 12.0 true @@ -20,7 +20,7 @@ - net7.0-windows;net6.0-windows;net481;net472;net462 + net8.0-windows;net7.0-windows;net6.0-windows;net481;net472;net462 diff --git a/Directory.Packages.props b/Directory.Packages.props index af80ca323..e4babf973 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,24 +1,24 @@ - - - - - + + + + + - - - + + + - + - + - - + + diff --git a/src/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj b/src/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj index 8b5051d0f..e61101205 100644 --- a/src/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj +++ b/src/Wpf.Ui.Demo.Mvvm/Wpf.Ui.Demo.Mvvm.csproj @@ -2,7 +2,7 @@ WinExe - net7.0-windows10.0.22621.0 + net8.0-windows10.0.22621.0 10.0.17763.0 enable enable diff --git a/src/Wpf.Ui.Demo.Simple/Wpf.Ui.Demo.Simple.csproj b/src/Wpf.Ui.Demo.Simple/Wpf.Ui.Demo.Simple.csproj index 4a2e8ef82..964b9e2d9 100644 --- a/src/Wpf.Ui.Demo.Simple/Wpf.Ui.Demo.Simple.csproj +++ b/src/Wpf.Ui.Demo.Simple/Wpf.Ui.Demo.Simple.csproj @@ -2,7 +2,7 @@ WinExe - net7.0-windows10.0.22621.0 + net8.0-windows10.0.22621.0 10.0.17763.0 enable true diff --git a/src/Wpf.Ui.FontMapper/Wpf.Ui.FontMapper.csproj b/src/Wpf.Ui.FontMapper/Wpf.Ui.FontMapper.csproj index 70403cb84..a372ae4ac 100644 --- a/src/Wpf.Ui.FontMapper/Wpf.Ui.FontMapper.csproj +++ b/src/Wpf.Ui.FontMapper/Wpf.Ui.FontMapper.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable enable 10.0 diff --git a/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj b/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj index 424a9cd7d..ac8e882a0 100644 --- a/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj +++ b/src/Wpf.Ui.Gallery/Wpf.Ui.Gallery.csproj @@ -2,7 +2,7 @@ WinExe - net7.0-windows10.0.22621.0 + net8.0-windows10.0.22621.0 enable enable true diff --git a/tests/Wpf.Ui.Gallery.UnitTests/Wpf.Ui.Gallery.UnitTests.csproj b/tests/Wpf.Ui.Gallery.UnitTests/Wpf.Ui.Gallery.UnitTests.csproj index 53962977c..540ff06e2 100644 --- a/tests/Wpf.Ui.Gallery.UnitTests/Wpf.Ui.Gallery.UnitTests.csproj +++ b/tests/Wpf.Ui.Gallery.UnitTests/Wpf.Ui.Gallery.UnitTests.csproj @@ -1,7 +1,7 @@ - net7.0-windows10.0.22621.0 + net8.0-windows10.0.22621.0 enable enable From 61c9107e64204650f0500e3376ddfd61a13940d7 Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:35:21 +0100 Subject: [PATCH 09/12] Bump .NET version --- .github/workflows/wpf-ui-cd-docs.yaml | 4 ++-- .github/workflows/wpf-ui-cd-nuget.yaml | 4 ++-- .github/workflows/wpf-ui-pr-validator.yaml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/wpf-ui-cd-docs.yaml b/.github/workflows/wpf-ui-cd-docs.yaml index d22faf3c4..8be32dba4 100644 --- a/.github/workflows/wpf-ui-cd-docs.yaml +++ b/.github/workflows/wpf-ui-cd-docs.yaml @@ -33,10 +33,10 @@ jobs: uses: actions/setup-node@v4 with: node-version: 18.x - - name: Setup .NET Core SDK 7.x + - name: Setup .NET Core SDK 8.x uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.x + dotnet-version: 8.x - name: Install docfx run: dotnet tool update -g docfx diff --git a/.github/workflows/wpf-ui-cd-nuget.yaml b/.github/workflows/wpf-ui-cd-nuget.yaml index 65427fbe8..10e30b1dd 100644 --- a/.github/workflows/wpf-ui-cd-nuget.yaml +++ b/.github/workflows/wpf-ui-cd-nuget.yaml @@ -17,10 +17,10 @@ jobs: - uses: nuget/setup-nuget@v1 with: nuget-api-key: ${{ secrets.NUGET_API_KEY }} - - name: Setup .NET Core SDK 7.x + - name: Setup .NET Core SDK 8.x uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.x + dotnet-version: 8.x - name: Install dependencies run: dotnet restore diff --git a/.github/workflows/wpf-ui-pr-validator.yaml b/.github/workflows/wpf-ui-pr-validator.yaml index b8f337907..858e1626f 100644 --- a/.github/workflows/wpf-ui-pr-validator.yaml +++ b/.github/workflows/wpf-ui-pr-validator.yaml @@ -19,10 +19,10 @@ jobs: - uses: nuget/setup-nuget@v1 with: nuget-api-key: ${{ secrets.NUGET_API_KEY }} - - name: Setup .NET Core SDK 7.x + - name: Setup .NET Core SDK 8.x uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.x + dotnet-version: 8.x - name: Install dependencies run: dotnet restore From 19fc9b7a2db980e4f5ddd026885881d7798f9079 Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:18:44 +0100 Subject: [PATCH 10/12] Format code --- Directory.Packages.props | 6 +- .../Appearance/ResourceDictionaryManager.cs | 2 +- src/Wpf.Ui/Appearance/SystemTheme.cs | 8 +- .../Appearance/WindowBackgroundManager.cs | 10 ++ .../CardControlAutomationPeer.cs | 23 ++-- .../Converters/IconSourceElementConverter.cs | 25 +++++ .../Extensions/NavigationServiceExtensions.cs | 6 + src/Wpf.Ui/Interop/UnsafeNativeMethods.cs | 104 ++++++++++++++---- 8 files changed, 140 insertions(+), 44 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index e4babf973..cddae1f54 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,7 +2,7 @@ - + @@ -18,7 +18,7 @@ - - + + diff --git a/src/Wpf.Ui/Appearance/ResourceDictionaryManager.cs b/src/Wpf.Ui/Appearance/ResourceDictionaryManager.cs index 832f82338..5f4b2fd2b 100644 --- a/src/Wpf.Ui/Appearance/ResourceDictionaryManager.cs +++ b/src/Wpf.Ui/Appearance/ResourceDictionaryManager.cs @@ -13,7 +13,7 @@ namespace Wpf.Ui.Appearance; internal class ResourceDictionaryManager { /// - /// Namespace, e.g. the library the resource is being searched for. + /// Gets the namespace, e.g. the library the resource is being searched for. /// public string SearchNamespace { get; } diff --git a/src/Wpf.Ui/Appearance/SystemTheme.cs b/src/Wpf.Ui/Appearance/SystemTheme.cs index e04ecc7ee..23cee95c1 100644 --- a/src/Wpf.Ui/Appearance/SystemTheme.cs +++ b/src/Wpf.Ui/Appearance/SystemTheme.cs @@ -51,22 +51,22 @@ public enum SystemTheme HC2, /// - /// First custom, kinda purple Windows 11 theme. + /// Dark theme: Glow /// Glow, /// - /// Second custom, kinda red Windows 11 theme. + /// Dark theme: Captured Motion /// CapturedMotion, /// - /// Third custom, kinda washed off cyan Windows 11 theme. + /// Light theme: Sunrise /// Sunrise, /// - /// Fourth custom, kinda gray Windows 11 theme. + /// Light theme: Flow /// Flow } diff --git a/src/Wpf.Ui/Appearance/WindowBackgroundManager.cs b/src/Wpf.Ui/Appearance/WindowBackgroundManager.cs index 67c7d9207..944e984f1 100644 --- a/src/Wpf.Ui/Appearance/WindowBackgroundManager.cs +++ b/src/Wpf.Ui/Appearance/WindowBackgroundManager.cs @@ -11,6 +11,16 @@ namespace Wpf.Ui.Appearance; /// /// Facilitates the management of the window background. /// +/// +/// +/// WindowBackgroundManager.UpdateBackground( +/// observedWindow.RootVisual, +/// currentApplicationTheme, +/// observedWindow.Backdrop, +/// observedWindow.ForceBackgroundReplace +/// ); +/// +/// public static class WindowBackgroundManager { /// diff --git a/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs b/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs index a2da2b312..a4f6dc739 100644 --- a/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs +++ b/src/Wpf.Ui/AutomationPeers/CardControlAutomationPeer.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +// 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 System.Windows.Automation; using System.Windows.Automation.Peers; using Wpf.Ui.Controls; @@ -17,7 +16,7 @@ internal class CardControlAutomationPeer : FrameworkElementAutomationPeer public CardControlAutomationPeer(CardControl owner) : base(owner) { - this._owner = owner; + _owner = owner; } protected override string GetClassNameCore() @@ -42,7 +41,7 @@ public override object GetPattern(PatternInterface patternInterface) protected override AutomationPeer GetLabeledByCore() { - if (this._owner.Header is UIElement element) + if (_owner.Header is UIElement element) { return CreatePeerForElement(element); } @@ -52,19 +51,19 @@ protected override AutomationPeer GetLabeledByCore() protected override string GetNameCore() { - string result = base.GetNameCore() ?? String.Empty; + var result = base.GetNameCore() ?? String.Empty; if (result == String.Empty) { - result = AutomationProperties.GetName(this._owner); + result = AutomationProperties.GetName(_owner); } - if (result == String.Empty && this._owner.Header is DependencyObject d) + if (result == String.Empty && _owner.Header is DependencyObject d) { result = AutomationProperties.GetName(d); } - if (result == String.Empty && this._owner.Header is string s) + if (result == String.Empty && _owner.Header is string s) { result = s; } diff --git a/src/Wpf.Ui/Converters/IconSourceElementConverter.cs b/src/Wpf.Ui/Converters/IconSourceElementConverter.cs index c787d5d09..58e30de06 100644 --- a/src/Wpf.Ui/Converters/IconSourceElementConverter.cs +++ b/src/Wpf.Ui/Converters/IconSourceElementConverter.cs @@ -8,18 +8,43 @@ namespace Wpf.Ui.Converters; +/// +/// Converts an to an . +/// public class IconSourceElementConverter : IValueConverter { + /// + /// Converts a value to an . + /// + /// The value to convert. + /// The type of the binding target property. + /// The converter parameter. + /// The culture to use in the converter. + /// The converted . public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { return ConvertToIconElement(value); } + /// + /// Converts an back to an IconSourceElement. + /// + /// The value to convert. + /// The type of the binding target property. + /// The converter parameter. + /// The culture to use in the converter. + /// The converted IconSourceElement. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotImplementedException(); } + /// + /// Converts a value to an . + /// + /// The dependency object (not used). + /// The base value to convert. + /// The converted IconElement. public static object ConvertToIconElement(DependencyObject _, object baseValue) { return ConvertToIconElement(baseValue); diff --git a/src/Wpf.Ui/Extensions/NavigationServiceExtensions.cs b/src/Wpf.Ui/Extensions/NavigationServiceExtensions.cs index 63524b073..61fcecc73 100644 --- a/src/Wpf.Ui/Extensions/NavigationServiceExtensions.cs +++ b/src/Wpf.Ui/Extensions/NavigationServiceExtensions.cs @@ -12,6 +12,12 @@ namespace Wpf.Ui.Extensions; /// public static class NavigationServiceExtensions { + /// + /// Sets the pane display mode of the navigation service. + /// + /// The navigation service. + /// The pane display mode. + /// Same so multiple calls can be chained. public static INavigationService SetPaneDisplayMode( this INavigationService navigationService, NavigationViewPaneDisplayMode paneDisplayMode diff --git a/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs b/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs index 380f466f3..f869da3fc 100644 --- a/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs +++ b/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs @@ -37,15 +37,19 @@ public static bool ApplyWindowCornerPreference(Window window, WindowCornerPrefer public static bool ApplyWindowCornerPreference(IntPtr handle, WindowCornerPreference cornerPreference) { if (handle == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(handle)) + { return false; + } int pvAttribute = (int)UnsafeReflection.Cast(cornerPreference); // TODO: Validate HRESULT - Dwmapi.DwmSetWindowAttribute( + _ = Dwmapi.DwmSetWindowAttribute( handle, Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref pvAttribute, @@ -71,19 +75,25 @@ public static bool RemoveWindowDarkMode(Window? window) => public static bool RemoveWindowDarkMode(IntPtr handle) { if (handle == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(handle)) + { return false; + } var pvAttribute = 0x0; // Disable var dwAttribute = Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE; if (!Win32.Utilities.IsOSWindows11Insider1OrNewer) + { dwAttribute = Dwmapi.DWMWINDOWATTRIBUTE.DMWA_USE_IMMERSIVE_DARK_MODE_OLD; + } // TODO: Validate HRESULT - Dwmapi.DwmSetWindowAttribute(handle, dwAttribute, ref pvAttribute, Marshal.SizeOf(typeof(int))); + _ = Dwmapi.DwmSetWindowAttribute(handle, dwAttribute, ref pvAttribute, Marshal.SizeOf(typeof(int))); return true; } @@ -104,19 +114,25 @@ public static bool ApplyWindowDarkMode(Window? window) => public static bool ApplyWindowDarkMode(IntPtr handle) { if (handle == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(handle)) + { return false; + } var pvAttribute = 0x1; // Enable var dwAttribute = Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE; if (!Win32.Utilities.IsOSWindows11Insider1OrNewer) + { dwAttribute = Dwmapi.DWMWINDOWATTRIBUTE.DMWA_USE_IMMERSIVE_DARK_MODE_OLD; + } // TODO: Validate HRESULT - Dwmapi.DwmSetWindowAttribute(handle, dwAttribute, ref pvAttribute, Marshal.SizeOf(typeof(int))); + _ = Dwmapi.DwmSetWindowAttribute(handle, dwAttribute, ref pvAttribute, Marshal.SizeOf(typeof(int))); return true; } @@ -129,10 +145,14 @@ public static bool ApplyWindowDarkMode(IntPtr handle) public static bool RemoveWindowTitlebarContents(Window? window) { if (window == null) + { return false; + } if (window.IsLoaded) + { return GetHandle(window, out IntPtr windowHandle) && RemoveWindowTitlebarContents(windowHandle); + } window.Loaded += (sender, _) => { @@ -151,10 +171,14 @@ public static bool RemoveWindowTitlebarContents(Window? window) public static bool RemoveWindowTitlebarContents(IntPtr handle) { if (handle == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(handle)) + { return false; + } var windowStyleLong = User32.GetWindowLong(handle, User32.GWL.GWL_STYLE); windowStyleLong &= ~(int)User32.WS.SYSMENU; @@ -173,18 +197,24 @@ public static bool RemoveWindowTitlebarContents(IntPtr handle) public static bool ApplyWindowBackdrop(IntPtr handle, WindowBackdropType backgroundType) { if (handle == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(handle)) + { return false; + } var backdropPvAttribute = (int)UnsafeReflection.Cast(backgroundType); if (backdropPvAttribute == (int)Dwmapi.DWMSBT.DWMSBT_DISABLE) + { return false; + } // TODO: Validate HRESULT - Dwmapi.DwmSetWindowAttribute( + _ = Dwmapi.DwmSetWindowAttribute( handle, Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, ref backdropPvAttribute, @@ -202,11 +232,13 @@ public static bool ApplyWindowBackdrop(IntPtr handle, WindowBackdropType backgro public static bool IsWindowHasBackdrop(IntPtr handle, WindowBackdropType backdropType) { if (!User32.IsWindow(handle)) + { return false; + } var pvAttribute = 0x0; - Dwmapi.DwmGetWindowAttribute( + _ = Dwmapi.DwmGetWindowAttribute( handle, Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, ref pvAttribute, @@ -230,11 +262,13 @@ public static bool IsWindowHasLegacyMica(Window? window) => public static bool IsWindowHasLegacyMica(IntPtr handle) { if (!User32.IsWindow(handle)) + { return false; + } var pvAttribute = 0x0; - Dwmapi.DwmGetWindowAttribute( + _ = Dwmapi.DwmGetWindowAttribute( handle, Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_MICA_EFFECT, ref pvAttribute, @@ -262,12 +296,12 @@ public static bool ApplyWindowLegacyMicaEffect(IntPtr handle) var backdropPvAttribute = 0x1; //Enable // TODO: Validate HRESULT - Dwmapi.DwmSetWindowAttribute( - handle, - Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_MICA_EFFECT, - ref backdropPvAttribute, - Marshal.SizeOf(typeof(int)) - ); + _ = Dwmapi.DwmSetWindowAttribute( + handle, + Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_MICA_EFFECT, + ref backdropPvAttribute, + Marshal.SizeOf(typeof(int)) + ); return true; } @@ -305,7 +339,7 @@ public static bool ApplyWindowLegacyAcrylicEffect(IntPtr handle) Data = accentPtr }; - User32.SetWindowCompositionAttribute(handle, ref data); + _ = User32.SetWindowCompositionAttribute(handle, ref data); Marshal.FreeHGlobal(accentPtr); @@ -332,15 +366,21 @@ public static Color GetDwmColor() internal static bool SetTaskbarState(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag) { if (hWnd == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(hWnd)) + { return false; + } var taskbarList = new ShObjIdl.CTaskbarList() as ShObjIdl.ITaskbarList4; if (taskbarList == null) + { return false; + } taskbarList.HrInit(); taskbarList.SetProgressState(hWnd, taskbarFlag); @@ -357,17 +397,22 @@ internal static bool SetTaskbarState(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag) internal static bool SetTaskbarValue(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag, int current, int total) { if (hWnd == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(hWnd)) + { return false; + } // TODO: Get existing taskbar class - var taskbarList = new ShObjIdl.CTaskbarList() as ShObjIdl.ITaskbarList4; - if (taskbarList == null) + if (taskbarList is null) + { return false; + } taskbarList.HrInit(); taskbarList.SetProgressState(hWnd, taskbarFlag); @@ -376,15 +421,19 @@ internal static bool SetTaskbarValue(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag, taskbarFlag != ShObjIdl.TBPFLAG.TBPF_INDETERMINATE && taskbarFlag != ShObjIdl.TBPFLAG.TBPF_NOPROGRESS ) + { taskbarList.SetProgressValue(hWnd, Convert.ToUInt64(current), Convert.ToUInt64(total)); + } return true; } public static bool RemoveWindowCaption(Window window) { - if (window == null) + if (window is null) + { return false; + } var windowHandle = new WindowInteropHelper(window).Handle; @@ -394,10 +443,14 @@ public static bool RemoveWindowCaption(Window window) public static bool RemoveWindowCaption(IntPtr hWnd) { if (hWnd == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(hWnd)) + { return false; + } var wtaOptions = new UxTheme.WTA_OPTIONS() { @@ -417,8 +470,10 @@ public static bool RemoveWindowCaption(IntPtr hWnd) public static bool ExtendClientAreaIntoTitleBar(Window window) { - if (window == null) + if (window is null) + { return false; + } var windowHandle = new WindowInteropHelper(window).Handle; @@ -433,10 +488,14 @@ public static bool ExtendClientAreaIntoTitleBar(IntPtr hWnd) // WinRt has ExtendContentIntoTitlebar, but it needs some digging if (hWnd == IntPtr.Zero) + { return false; + } if (!User32.IsWindow(hWnd)) + { return false; + } // #1 Remove titlebar elements var wtaOptions = new UxTheme.WTA_OPTIONS() @@ -454,10 +513,10 @@ public static bool ExtendClientAreaIntoTitleBar(IntPtr hWnd) (uint)Marshal.SizeOf(typeof(UxTheme.WTA_OPTIONS)) ); - var windowDpi = DpiHelper.GetWindowDpi(hWnd); + DisplayDpi windowDpi = DpiHelper.GetWindowDpi(hWnd); // #2 Extend glass frame - var deviceGlassThickness = DpiHelper.LogicalThicknessToDevice( + Thickness deviceGlassThickness = DpiHelper.LogicalThicknessToDevice( new Thickness(-1, -1, -1, -1), windowDpi.DpiScaleX, windowDpi.DpiScaleY @@ -484,10 +543,9 @@ public static bool ExtendClientAreaIntoTitleBar(IntPtr hWnd) /// /// Checks whether the DWM composition is enabled. /// - /// public static bool IsCompositionEnabled() { - Dwmapi.DwmIsCompositionEnabled(out var isEnabled); + _ = Dwmapi.DwmIsCompositionEnabled(out var isEnabled); return isEnabled == 0x1; } @@ -503,12 +561,10 @@ public static bool IsValidWindow(IntPtr hWnd) /// /// Tries to get the pointer to the window handle. /// - /// - /// /// if the handle is not . private static bool GetHandle(Window? window, out IntPtr windowHandle) { - if (window == null) + if (window is null) { windowHandle = IntPtr.Zero; From 01e464fd2c7bc9360b2fdfc4ebae82f7d4520c16 Mon Sep 17 00:00:00 2001 From: Mahdi Hosseini Date: Wed, 22 Nov 2023 19:59:28 +0330 Subject: [PATCH 11/12] Fix SetWindowLong for x86 #803 (#825) * Fix #803 * Move declarations * Update if statement * Update marshall declaration --------- Co-authored-by: pomianowski <13592821+pomianowski@users.noreply.github.com> --- src/Wpf.Ui/Interop/UnsafeNativeMethods.cs | 15 +++++++++++++-- src/Wpf.Ui/Interop/User32.cs | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs b/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs index 380f466f3..d4ce862f8 100644 --- a/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs +++ b/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs @@ -159,9 +159,10 @@ public static bool RemoveWindowTitlebarContents(IntPtr handle) var windowStyleLong = User32.GetWindowLong(handle, User32.GWL.GWL_STYLE); windowStyleLong &= ~(int)User32.WS.SYSMENU; - var result = User32.SetWindowLong(handle, User32.GWL.GWL_STYLE, windowStyleLong); + IntPtr result = SetWindowLong(handle, User32.GWL.GWL_STYLE, windowStyleLong); + long resultValue = result.ToInt64(); - return result > 0x0; + return resultValue > 0x0; } /// @@ -519,4 +520,14 @@ private static bool GetHandle(Window? window, out IntPtr windowHandle) return windowHandle != IntPtr.Zero; } + + private static IntPtr SetWindowLong(IntPtr handle, User32.GWL nIndex, long windowStyleLong) + { + if (IntPtr.Size == 4) + { + return new IntPtr(User32.SetWindowLong(handle, (int)nIndex, (int)windowStyleLong)); + } + + return User32.SetWindowLongPtr(handle, (int)nIndex, (IntPtr)windowStyleLong); + } } diff --git a/src/Wpf.Ui/Interop/User32.cs b/src/Wpf.Ui/Interop/User32.cs index 3ab2bf49d..bb08a8f1e 100644 --- a/src/Wpf.Ui/Interop/User32.cs +++ b/src/Wpf.Ui/Interop/User32.cs @@ -1308,6 +1308,12 @@ [In] IntPtr lParam [DllImport(Libraries.User32, CharSet = CharSet.Auto)] public static extern IntPtr SetWindowLongPtr([In] IntPtr hWnd, [In] int nIndex, [In] IntPtr dwNewLong); + /// + /// Changes an attribute of the specified window. + /// + [DllImport(Libraries.User32, CharSet = CharSet.Auto, SetLastError = true)] + public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + /// /// Destroys an icon and frees any memory the icon occupied. /// From c00d428915f20ed114bc521db41e7094abaf81ed Mon Sep 17 00:00:00 2001 From: pomianowski <13592821+pomianowski@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:30:36 +0100 Subject: [PATCH 12/12] Update native methods --- src/Wpf.Ui/Interop/UnsafeNativeMethods.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs b/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs index 516a0369a..2a706aa93 100644 --- a/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs +++ b/src/Wpf.Ui/Interop/UnsafeNativeMethods.cs @@ -183,10 +183,9 @@ public static bool RemoveWindowTitlebarContents(IntPtr handle) var windowStyleLong = User32.GetWindowLong(handle, User32.GWL.GWL_STYLE); windowStyleLong &= ~(int)User32.WS.SYSMENU; - IntPtr result = SetWindowLong(handle, User32.GWL.GWL_STYLE, windowStyleLong); - long resultValue = result.ToInt64(); + var result = SetWindowLong(handle, User32.GWL.GWL_STYLE, windowStyleLong); - return resultValue > 0x0; + return result.ToInt64() > 0x0; } ///