From 43e0442200eb6727bc3cef47b445192362374296 Mon Sep 17 00:00:00 2001 From: NotYoojun Date: Wed, 31 Jan 2024 14:35:45 +0800 Subject: [PATCH] Remove some helpers --- .../Common/Extensions.cs | 1 + .../Common/PopupHelper.cs | 1 + .../Controls/AutoSuggestBox/AutoSuggestBox.cs | 2 + .../AutoSuggestBox/AutoSuggestBoxListView.cs | 1 + .../Controls/CommandBar/AppBarButton.cs | 2 + .../Controls/CommandBar/AppBarRepeatButton.cs | 2 + .../Controls/CommandBar/AppBarToggleButton.cs | 2 + .../Controls/CommandBar/CommandBarToolBar.cs | 2 + .../CommandBarFlyoutToolBar.cs | 1 + .../Controls/ContentDialog/ContentDialog.cs | 1 + .../Controls/Flyout/FlyoutBase.cs | 1 + .../MediaPlayerElement/MediaElementEx.cs | 1 + .../MediaTransportControls.cs | 3 +- .../Controls/NavigationView/NavigationView.cs | 1 + .../NavigationViewItemPresenter.cs | 3 +- .../Controls/ParallaxView/ParallaxView.cs | 1 + .../ItemsRepeater/ItemsRepeaterScrollHost.cs | 1 + .../Controls/SplitView/SplitView.cs | 1 + .../iNKORE.UI.WPF.Modern.Controls.csproj | 6 +- .../Common/WindowHelper.cs | 3 +- .../Helper/ThemeHelper.cs | 1 + .../ItemPage.xaml.cs | 1 + .../Navigation/NavigationRootPage.xaml.cs | 1 + .../SampleSystemBackdropsWindow.xaml.cs | 3 +- .../SearchResultsPage.xaml.cs | 1 + .../SettingsPage.xaml.cs | 1 + .../Common/VisualStateGroupHelper.cs | 1 + .../Controls/Helpers/DatePickerHelper.cs | 3 +- .../Controls/Helpers/ExpanderHelper.cs | 3 +- .../Helpers/OpeningAnimationHelper.cs | 3 +- .../Controls/Helpers/PasswordBoxHelper.cs | 3 +- .../Controls/Helpers/TabControlHelper.cs | 3 +- .../Controls/Helpers/TabItemHelper.cs | 3 +- .../Controls/Helpers/WindowHelper.cs | 1 + .../Primitives/MaximizedWindowFixer.cs | 3 +- .../Controls/Primitives/PanelHelper.cs | 3 +- .../Controls/Primitives/PopupPositioner.cs | 2 + .../Controls/XamlControlsResources.cs | 3 +- .../Helpers/AnimationHelper.cs | 47 -- .../Helpers/ColorsHelper.cs | 1 + .../Helpers/ControlExtensions.cs | 23 - .../Helpers/DelegateHelper.cs | 82 ---- .../Helpers/DesignMode.cs | 21 - .../Helpers/DispatcherExtensions.cs | 418 ----------------- .../Helpers/DispatcherHelper.cs | 419 ------------------ .../Helpers/DoubleUtil.cs | 14 - .../iNKORE.UI.WPF.Modern/Helpers/DpiHelper.cs | 83 ---- .../Helpers/Extensions.cs | 20 - .../Helpers/FontHelper.cs | 53 --- .../Helpers/GridLengthHelper.cs | 17 - .../Helpers/MenuDropAlignmentHelper.cs | 55 --- .../Helpers/MergedDictionariesHelper.cs | 127 ------ .../Helpers/OSVersionHelper.cs | 49 -- .../Helpers/PackagedAppHelper.cs | 33 -- .../Helpers/Styles/AcrylicHelper.cs | 3 +- .../Helpers/Styles/MicaHelper.cs | 3 +- .../Helpers/Styles/SnapLayout.cs | 3 +- .../Helpers/ThicknessHelper.cs | 17 - .../Helpers/VisualTree.cs | 230 ---------- source/iNKORE.UI.WPF.Modern/ThemeManager.cs | 3 +- source/iNKORE.UI.WPF.Modern/ThemeResources.cs | 3 +- .../DesignTime/IntellisenseResourcesBase.cs | 3 +- .../UISettingsResources.cs | 1 + .../iNKORE.UI.WPF.Modern.csproj | 6 +- 64 files changed, 80 insertions(+), 1729 deletions(-) delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/AnimationHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/ControlExtensions.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/DelegateHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/DesignMode.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/DispatcherExtensions.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/DispatcherHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/DoubleUtil.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/DpiHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/Extensions.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/FontHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/GridLengthHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/MenuDropAlignmentHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/MergedDictionariesHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/OSVersionHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/PackagedAppHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/ThicknessHelper.cs delete mode 100644 source/iNKORE.UI.WPF.Modern/Helpers/VisualTree.cs diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Common/Extensions.cs b/source/iNKORE.UI.WPF.Modern.Controls/Common/Extensions.cs index 2b520ea..33dee50 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Common/Extensions.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Common/Extensions.cs @@ -4,6 +4,7 @@ using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; using iNKORE.UI.WPF.Modern.Controls; +using iNKORE.UI.WPF.Helpers; namespace iNKORE.UI.WPF.Modern.Common { diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Common/PopupHelper.cs b/source/iNKORE.UI.WPF.Modern.Controls/Common/PopupHelper.cs index bda9b4d..dece2c6 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Common/PopupHelper.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Common/PopupHelper.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Windows.Controls.Primitives; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/AutoSuggestBox/AutoSuggestBox.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/AutoSuggestBox/AutoSuggestBox.cs index 811a0a0..fc7bd5f 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/AutoSuggestBox/AutoSuggestBox.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/AutoSuggestBox/AutoSuggestBox.cs @@ -8,11 +8,13 @@ using System.Windows.Documents; using System.Windows.Input; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Common.Converters; using iNKORE.UI.WPF.Modern.Controls.Helpers; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; +using ControlHelper = iNKORE.UI.WPF.Modern.Controls.Helpers.ControlHelper; namespace iNKORE.UI.WPF.Modern.Controls { diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/AutoSuggestBox/AutoSuggestBoxListView.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/AutoSuggestBox/AutoSuggestBoxListView.cs index 2f4dda1..e49481f 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/AutoSuggestBox/AutoSuggestBoxListView.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/AutoSuggestBox/AutoSuggestBoxListView.cs @@ -2,6 +2,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Helpers; namespace iNKORE.UI.WPF.Modern.Controls.Primitives diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarButton.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarButton.cs index ac212c7..5b1a066 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarButton.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarButton.cs @@ -1,9 +1,11 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Controls.Helpers; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; +using ControlHelper = iNKORE.UI.WPF.Modern.Controls.Helpers.ControlHelper; namespace iNKORE.UI.WPF.Modern.Controls { diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarRepeatButton.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarRepeatButton.cs index 6e12248..166ff7f 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarRepeatButton.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarRepeatButton.cs @@ -1,9 +1,11 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Controls.Helpers; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; +using ControlHelper = iNKORE.UI.WPF.Modern.Controls.Helpers.ControlHelper; namespace iNKORE.UI.WPF.Modern.Controls { diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarToggleButton.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarToggleButton.cs index 7ab00f2..266aa96 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarToggleButton.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/AppBarToggleButton.cs @@ -1,9 +1,11 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Controls.Helpers; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; +using ControlHelper = iNKORE.UI.WPF.Modern.Controls.Helpers.ControlHelper; namespace iNKORE.UI.WPF.Modern.Controls { diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/CommandBarToolBar.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/CommandBarToolBar.cs index 62f158a..a9aa95c 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/CommandBarToolBar.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBar/CommandBarToolBar.cs @@ -5,9 +5,11 @@ using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Controls.Helpers; using iNKORE.UI.WPF.Modern.Helpers; +using ControlHelper = iNKORE.UI.WPF.Modern.Controls.Helpers.ControlHelper; namespace iNKORE.UI.WPF.Modern.Controls.Primitives { diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBarFlyout/CommandBarFlyoutToolBar.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBarFlyout/CommandBarFlyoutToolBar.cs index 37c6490..0e47338 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBarFlyout/CommandBarFlyoutToolBar.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/CommandBarFlyout/CommandBarFlyoutToolBar.cs @@ -12,6 +12,7 @@ using System.Windows.Input; using System.Windows.Media.Animation; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Helpers; diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/ContentDialog/ContentDialog.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/ContentDialog/ContentDialog.cs index dfc5389..4aa9aed 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/ContentDialog/ContentDialog.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/ContentDialog/ContentDialog.cs @@ -9,6 +9,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/Flyout/FlyoutBase.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/Flyout/FlyoutBase.cs index d5bca9c..42fbe90 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/Flyout/FlyoutBase.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/Flyout/FlyoutBase.cs @@ -8,6 +8,7 @@ using System.Windows.Documents; using System.Windows.Input; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Controls.Helpers; using iNKORE.UI.WPF.Modern.Helpers; diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/MediaPlayerElement/MediaElementEx.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/MediaPlayerElement/MediaElementEx.cs index d7e9cd5..2cd0045 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/MediaPlayerElement/MediaElementEx.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/MediaPlayerElement/MediaElementEx.cs @@ -7,6 +7,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Helpers; namespace iNKORE.UI.WPF.Modern.Controls diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/MediaPlayerElement/MediaTransportControls.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/MediaPlayerElement/MediaTransportControls.cs index 55d491b..464cfdd 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/MediaPlayerElement/MediaTransportControls.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/MediaPlayerElement/MediaTransportControls.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Common.Converters; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Common.Converters; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; using iNKORE.UI.WPF.Modern.Markup; diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/NavigationView/NavigationView.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/NavigationView/NavigationView.cs index e79dffd..7f08303 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/NavigationView/NavigationView.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/NavigationView/NavigationView.cs @@ -16,6 +16,7 @@ using System.Windows.Media.Animation; using System.Windows.Shell; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Automation.Peers; using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Controls.Primitives; diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/NavigationView/NavigationViewItemPresenter.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/NavigationView/NavigationViewItemPresenter.cs index 9627bd1..e766a2a 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/NavigationView/NavigationViewItemPresenter.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/NavigationView/NavigationViewItemPresenter.cs @@ -6,12 +6,13 @@ using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Controls.Helpers; using iNKORE.UI.WPF.Modern.Helpers; using iNKORE.UI.WPF.Modern.Input; using static CppWinRTHelpers; -using static iNKORE.UI.WPF.Modern.Controls.NavigationViewItemHelper; +using ControlHelper = iNKORE.UI.WPF.Modern.Controls.Helpers.ControlHelper; namespace iNKORE.UI.WPF.Modern.Controls.Primitives { diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/ParallaxView/ParallaxView.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/ParallaxView/ParallaxView.cs index b056b2a..7f15f3b 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/ParallaxView/ParallaxView.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/ParallaxView/ParallaxView.cs @@ -11,6 +11,7 @@ using System.Windows.Media; using System.Windows; using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; namespace iNKORE.UI.WPF.Modern.Controls { diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/Repeater/ItemsRepeater/ItemsRepeaterScrollHost.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/Repeater/ItemsRepeater/ItemsRepeaterScrollHost.cs index 9071b13..fb2dfea 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/Repeater/ItemsRepeater/ItemsRepeaterScrollHost.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/Repeater/ItemsRepeater/ItemsRepeaterScrollHost.cs @@ -8,6 +8,7 @@ using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Markup; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Helpers; namespace iNKORE.UI.WPF.Modern.Controls diff --git a/source/iNKORE.UI.WPF.Modern.Controls/Controls/SplitView/SplitView.cs b/source/iNKORE.UI.WPF.Modern.Controls/Controls/SplitView/SplitView.cs index 0fe90b3..d2c3acf 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/Controls/SplitView/SplitView.cs +++ b/source/iNKORE.UI.WPF.Modern.Controls/Controls/SplitView/SplitView.cs @@ -5,6 +5,7 @@ using System.Windows.Markup; using System.Windows.Media; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; diff --git a/source/iNKORE.UI.WPF.Modern.Controls/iNKORE.UI.WPF.Modern.Controls.csproj b/source/iNKORE.UI.WPF.Modern.Controls/iNKORE.UI.WPF.Modern.Controls.csproj index c78471b..3f27a9c 100644 --- a/source/iNKORE.UI.WPF.Modern.Controls/iNKORE.UI.WPF.Modern.Controls.csproj +++ b/source/iNKORE.UI.WPF.Modern.Controls/iNKORE.UI.WPF.Modern.Controls.csproj @@ -1,7 +1,7 @@  - net6.0-windows10.0.18362.0;net452 + net6.0-windows10.0.18362.0;net462 true en-US $(TargetsForTfmSpecificBuildOutput);GetDocumentationFile @@ -77,6 +77,10 @@ + + + + diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Common/WindowHelper.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Common/WindowHelper.cs index 2854961..1f21057 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Common/WindowHelper.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Common/WindowHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System; using System.Collections.Generic; using System.Linq; diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Helper/ThemeHelper.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Helper/ThemeHelper.cs index aacd944..8e93218 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Helper/ThemeHelper.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Helper/ThemeHelper.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Windows; using Windows.Storage; +using iNKORE.UI.WPF.Helpers; namespace iNKORE.UI.WPF.Modern.Gallery.Helper { diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs index e7fe58e..e4cfce2 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs @@ -23,6 +23,7 @@ using Windows.System.Profile; using Frame = iNKORE.UI.WPF.Modern.Controls.Frame; using Page = iNKORE.UI.WPF.Modern.Controls.Page; +using iNKORE.UI.WPF.Helpers; namespace iNKORE.UI.WPF.Modern.Gallery { diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Navigation/NavigationRootPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Navigation/NavigationRootPage.xaml.cs index 0d03e5e..572bfff 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Navigation/NavigationRootPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Navigation/NavigationRootPage.xaml.cs @@ -27,6 +27,7 @@ using Frame = iNKORE.UI.WPF.Modern.Controls.Frame; using iNKORE.UI.WPF.Modern.Gallery.Common; using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; namespace iNKORE.UI.WPF.Modern.Gallery { diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs index 18957ae..1a9d7a0 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Controls.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Controls.Helpers; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; using iNKORE.UI.WPF.Modern.Helpers.Styles; diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs index 2ec3af4..47ba2d2 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs @@ -17,6 +17,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using iNKORE.UI.WPF.Helpers; namespace iNKORE.UI.WPF.Modern.Gallery { diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs index 7bf2d13..6b2fc56 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs @@ -21,6 +21,7 @@ using iNKORE.UI.WPF.Modern.Gallery.Helper; using System.Reflection; using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; namespace iNKORE.UI.WPF.Modern.Gallery { diff --git a/source/iNKORE.UI.WPF.Modern/Common/VisualStateGroupHelper.cs b/source/iNKORE.UI.WPF.Modern/Common/VisualStateGroupHelper.cs index 64385dc..3b8d8af 100644 --- a/source/iNKORE.UI.WPF.Modern/Common/VisualStateGroupHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Common/VisualStateGroupHelper.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Helpers; using System; using System.Collections.ObjectModel; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/DatePickerHelper.cs b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/DatePickerHelper.cs index fa950ae..5632a37 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/DatePickerHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/DatePickerHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System; using System.Globalization; using System.Windows; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/ExpanderHelper.cs b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/ExpanderHelper.cs index cee9300..14857a6 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/ExpanderHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/ExpanderHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System; using System.Collections.Generic; using System.Linq; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/OpeningAnimationHelper.cs b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/OpeningAnimationHelper.cs index dcdb666..bbdb607 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/OpeningAnimationHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/OpeningAnimationHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System.Windows; using System.Windows.Media.Animation; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/PasswordBoxHelper.cs b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/PasswordBoxHelper.cs index 888c4ed..59e5eaa 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/PasswordBoxHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/PasswordBoxHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Common; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Helpers; using System.Windows; using System.Windows.Controls; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabControlHelper.cs b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabControlHelper.cs index 0b7ed97..5956107 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabControlHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabControlHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Common; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Helpers; using System; using System.Windows; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabItemHelper.cs b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabItemHelper.cs index ab4a358..5171150 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabItemHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabItemHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Common; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Helpers; using System; using System.Windows; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/WindowHelper.cs b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/WindowHelper.cs index 5aaa6b2..ab94240 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Helpers/WindowHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Helpers/WindowHelper.cs @@ -1,5 +1,6 @@ using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Helpers.Styles; using System; using System.ComponentModel; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Primitives/MaximizedWindowFixer.cs b/source/iNKORE.UI.WPF.Modern/Controls/Primitives/MaximizedWindowFixer.cs index 506ddb0..c570ce0 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Primitives/MaximizedWindowFixer.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Primitives/MaximizedWindowFixer.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using iNKORE.UI.WPF.Modern.Native; using System; using System.ComponentModel; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Primitives/PanelHelper.cs b/source/iNKORE.UI.WPF.Modern/Controls/Primitives/PanelHelper.cs index abf305b..c24f271 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Primitives/PanelHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Primitives/PanelHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System.ComponentModel; using System.Windows; using System.Windows.Controls; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Primitives/PopupPositioner.cs b/source/iNKORE.UI.WPF.Modern/Controls/Primitives/PopupPositioner.cs index 0a53aeb..54fec0f 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Primitives/PopupPositioner.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Primitives/PopupPositioner.cs @@ -13,6 +13,8 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; + //using Windows.Win32.Foundation; //using Windows.Win32.UI.WindowsAndMessaging; using iNKORE.UI.WPF.Modern.Helpers; diff --git a/source/iNKORE.UI.WPF.Modern/Controls/XamlControlsResources.cs b/source/iNKORE.UI.WPF.Modern/Controls/XamlControlsResources.cs index 8ad7fcd..f769a83 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/XamlControlsResources.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/XamlControlsResources.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System.Windows; namespace iNKORE.UI.WPF.Modern.Controls diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/AnimationHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/AnimationHelper.cs deleted file mode 100644 index 951793f..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/AnimationHelper.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Diagnostics; -using System.Windows; -using System.Windows.Media.Animation; -using System.Windows.Threading; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class AnimationHelper - { - public static void DeferBegin(Storyboard storyboard) - { - storyboard.CurrentStateInvalidated += OnStoryboardCurrentStateInvalidated; - - static void OnStoryboardCurrentStateInvalidated(object sender, EventArgs e) - { - if (sender is Clock clock && - clock.HasControllableRoot && - clock.CurrentState == ClockState.Active && - !clock.IsPaused) - { - clock.Controller.Pause(); - clock.Dispatcher.BeginInvoke(() => - { - Debug.Assert(clock.IsPaused || clock.CurrentState != ClockState.Active); - if (clock.IsPaused) - { - clock.Controller.Resume(); - } - }, DispatcherPriority.Loaded); - } - } - } - - public static void DeferTransitions(VisualStateGroup group) - { - foreach (VisualTransition transition in group.Transitions) - { - var storyboard = transition.Storyboard; - if (storyboard != null) - { - DeferBegin(storyboard); - } - } - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/ColorsHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/ColorsHelper.cs index 46d130f..b6270cc 100644 --- a/source/iNKORE.UI.WPF.Modern/Helpers/ColorsHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Helpers/ColorsHelper.cs @@ -7,6 +7,7 @@ using Microsoft.Win32; using iNKORE.UI.WPF.Modern.Media.ColorPalette; using Windows.UI.ViewManagement; +using iNKORE.UI.WPF.Helpers; namespace iNKORE.UI.WPF.Modern.Helpers { diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/ControlExtensions.cs b/source/iNKORE.UI.WPF.Modern/Helpers/ControlExtensions.cs deleted file mode 100644 index 926817c..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/ControlExtensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class ControlExtensions - { - public static FrameworkElement GetTemplateRoot(this Control control) - { - if (VisualTreeHelper.GetChildrenCount(control) > 0) - { - return VisualTreeHelper.GetChild(control, 0) as FrameworkElement; - } - return null; - } - - public static T GetTemplateChild(this Control control, string childName) where T : DependencyObject - { - return control.Template?.FindName(childName, control) as T; - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/DelegateHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/DelegateHelper.cs deleted file mode 100644 index b96632d..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/DelegateHelper.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Reflection; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class DelegateHelper - { - public static T CreateDelegate(MethodInfo method) where T : Delegate - { - return (T)Delegate.CreateDelegate(typeof(T), method); - } - - public static T CreateDelegate(object firstArgument, MethodInfo method) where T : Delegate - { - return (T)Delegate.CreateDelegate(typeof(T), firstArgument, method); - } - - public static T CreateDelegate(Type target, string method, BindingFlags bindingAttr = DefaultLookup) where T : Delegate - { - if (bindingAttr != DefaultLookup) - { - var methodInfo = target.GetMethod(method, bindingAttr); - if (methodInfo != null) - { - return CreateDelegate(methodInfo); - } - return null; - } - else - { - return (T)Delegate.CreateDelegate(typeof(T), target, method); - } - } - - public static T CreateDelegate(object target, string method, BindingFlags bindingAttr = DefaultLookup) where T : Delegate - { - if (bindingAttr != DefaultLookup) - { - var methodInfo = target.GetType().GetMethod(method, bindingAttr); - if (methodInfo != null) - { - return CreateDelegate(target, methodInfo); - } - return null; - } - else - { - return (T)Delegate.CreateDelegate(typeof(T), target, method); - } - } - - public static Func CreatePropertyGetter(string name, BindingFlags bindingAttr = DefaultLookup, bool nonPublic = false) - { - var property = typeof(TType).GetProperty(name, bindingAttr); - if (property != null) - { - var getMethod = property.GetGetMethod(nonPublic); - if (getMethod != null) - { - return CreateDelegate>(getMethod); - } - } - return null; - } - - public static Action CreatePropertySetter(string name, BindingFlags bindingAttr = DefaultLookup, bool nonPublic = false) - { - var property = typeof(TType).GetProperty(name, bindingAttr); - if (property != null) - { - var setMethod = property.GetSetMethod(nonPublic); - if (setMethod != null) - { - return CreateDelegate>(setMethod); - } - } - return null; - } - - private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/DesignMode.cs b/source/iNKORE.UI.WPF.Modern/Helpers/DesignMode.cs deleted file mode 100644 index 535cf10..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/DesignMode.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.ComponentModel; -using System.Windows; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - /// - /// Enables you to detect whether your app is in design mode in a visual designer. - /// - internal static class DesignMode - { - private static readonly Lazy _designModeEnabled = - new Lazy(() => DesignerProperties.GetIsInDesignMode(new DependencyObject())); - - /// - /// Gets a value that indicates whether the process is running in design mode. - /// - /// **True** if the process is running in design mode; otherwise **false**. - public static bool DesignModeEnabled => _designModeEnabled.Value; - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/DispatcherExtensions.cs b/source/iNKORE.UI.WPF.Modern/Helpers/DispatcherExtensions.cs deleted file mode 100644 index 1b924ad..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/DispatcherExtensions.cs +++ /dev/null @@ -1,418 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ComponentModel; // EditorBrowsableAttribute, BrowsableAttribute -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Threading; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - /// - /// Helpers for executing code in a . - /// - public static class DispatcherExtensions - { -#if !NETCOREAPP - /// - /// Executes the specified delegate asynchronously - /// on the thread that the Dispatcher was created on. - /// - /// - /// Dispatcher that executes the specified method - /// - /// - /// A delegate to a no argument no return type method - /// - /// - /// An IAsyncResult object that represents the result of the - /// BeginInvoke operation. - /// - /// - /// This method is now part of the Dispatcher class. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public static DispatcherOperation BeginInvoke(this Dispatcher dispatcher, Action action) - { - return dispatcher.BeginInvoke(action); - } - - /// - /// Executes the specified delegate asynchronously - /// on the thread that the Dispatcher was created on. - /// - /// - /// Dispatcher that executes the specified method - /// - /// - /// A delegate to a no argument no return type method - /// - /// - /// The priority that determines in what order the specified method - /// is invoked relative to the other pending methods in the Dispatcher. - /// - /// - /// An IAsyncResult object that represents the result of the - /// BeginInvoke operation. - /// - /// - /// This method is now part of the Dispatcher class. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public static DispatcherOperation BeginInvoke(this Dispatcher dispatcher, Action action, DispatcherPriority priority) - { - return dispatcher.BeginInvoke(action, priority); - } - - /// - /// Executes the specified delegate synchronously on the thread that - /// the Dispatcher was created on. - /// - /// - /// Dispatcher that executes the specified method - /// - /// - /// A delegate to a no argument no return type method - /// - /// - /// This method is now part of the Dispatcher class. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public static void Invoke(this Dispatcher dispatcher, Action action) - { - dispatcher.Invoke(action); - } - - /// - /// Executes the specified delegate synchronously on the thread that - /// the Dispatcher was created on. - /// - /// - /// Dispatcher that executes the specified method - /// - /// - /// A delegate to a no argument no return type method - /// - /// - /// The priority that determines in what order the specified method - /// is invoked relative to the other pending methods in the Dispatcher. - /// - /// - /// This method is now part of the Dispatcher class. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public static void Invoke(this Dispatcher dispatcher, Action action, DispatcherPriority priority) - { - dispatcher.Invoke(action, priority); - } - - /// - /// Executes the specified delegate synchronously on the thread that - /// the Dispatcher was created on. - /// - /// - /// Dispatcher that executes the specified method - /// - /// - /// A delegate to a no argument no return type method - /// - /// - /// The maximum amount of time to wait for the operation to complete. - /// - /// - /// This method is now part of the Dispatcher class. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public static void Invoke(this Dispatcher dispatcher, Action action, TimeSpan timeout) - { - dispatcher.Invoke(action, timeout); - } - - /// - /// Executes the specified delegate synchronously on the thread that - /// the Dispatcher was created on. - /// - /// - /// Dispatcher that executes the specified method - /// - /// - /// A delegate to a no argument no return type method - /// - /// - /// The maximum amount of time to wait for the operation to complete. - /// - /// - /// The priority that determines in what order the specified method - /// is invoked relative to the other pending methods in the Dispatcher. - /// - /// - /// This method is now part of the Dispatcher class. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public static void Invoke(this Dispatcher dispatcher, Action action, TimeSpan timeout, DispatcherPriority priority) - { - dispatcher.Invoke(action, timeout, priority); - } -#endif - - /// - /// Invokes a given function on the target and returns a - /// that completes when the invocation of the function is completed. - /// - /// The target to invoke the code on. - /// The to invoke. - /// The priority level for the function to invoke. - /// A that completes when the invocation of is over. - /// If the current thread has access to , will be invoked directly. - public static Task EnqueueAsync(this Dispatcher dispatcher, Action function, DispatcherPriority priority = DispatcherPriority.Normal) - { - // Run the function directly when we have thread access. - // Also reuse Task.CompletedTask in case of success, - // to skip an unnecessary heap allocation for every invocation. - if (dispatcher.CheckAccess()) - { - try - { - function(); -#if !NET452 - return Task.CompletedTask; -#else - return new Task(() => { }, default, (TaskCreationOptions)16384); -#endif - } - catch (Exception e) - { -#if !NET452 - return Task.FromException(e); -#else - return new Task(() => throw e); -#endif - } - } - - static Task TryEnqueueAsync(Dispatcher dispatcher, Action function, DispatcherPriority priority) - { - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher.InvokeAsync(() => - { - try - { - function(); - - taskCompletionSource.SetResult(null); - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }, priority); - - return taskCompletionSource.Task; - } - - return TryEnqueueAsync(dispatcher, function, priority); - } - - /// - /// Invokes a given function on the target and returns a - /// that completes when the invocation of the function is completed. - /// - /// The return type of to relay through the returned . - /// The target to invoke the code on. - /// The to invoke. - /// The priority level for the function to invoke. - /// A that completes when the invocation of is over. - /// If the current thread has access to , will be invoked directly. - public static Task EnqueueAsync(this Dispatcher dispatcher, Func function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (dispatcher.CheckAccess()) - { - try - { - return Task.FromResult(function()); - } - catch (Exception e) - { -#if !NET452 - return Task.FromException(e); -#else - return new Task(() => throw e); -#endif - } - } - - static Task TryEnqueueAsync(Dispatcher dispatcher, Func function, DispatcherPriority priority) - { - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher.InvokeAsync(() => - { - try - { - taskCompletionSource.SetResult(function()); - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }, priority); - - return taskCompletionSource.Task; - } - - return TryEnqueueAsync(dispatcher, function, priority); - } - - /// - /// Invokes a given function on the target and returns a - /// that acts as a proxy for the one returned by the given function. - /// - /// The target to invoke the code on. - /// The to invoke. - /// The priority level for the function to invoke. - /// A that acts as a proxy for the one returned by . - /// If the current thread has access to , will be invoked directly. - public static Task EnqueueAsync(this Dispatcher dispatcher, Func function, DispatcherPriority priority = DispatcherPriority.Normal) - { - // If we have thread access, we can retrieve the task directly. - // We don't use ConfigureAwait(false) in this case, in order - // to let the caller continue its execution on the same thread - // after awaiting the task returned by this function. - if (dispatcher.CheckAccess()) - { - try - { - if (function() is Task awaitableResult) - { - return awaitableResult; - } -#if !NET452 - return Task.FromException(new InvalidOperationException("The Task returned by function cannot be null.")); -#else - return new Task(() => throw new InvalidOperationException("The Task returned by function cannot be null.")); -#endif - } - catch (Exception e) - { -#if !NET452 - return Task.FromException(e); -#else - return new Task(() => throw e); -#endif - } - } - - static Task TryEnqueueAsync(Dispatcher dispatcher, Func function, DispatcherPriority priority) - { - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher.InvokeAsync(async () => - { - try - { - if (function() is Task awaitableResult) - { - await awaitableResult.ConfigureAwait(false); - - taskCompletionSource.SetResult(null); - } - else - { - taskCompletionSource.SetException(GetEnqueueException("The Task returned by function cannot be null.")); - } - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }, priority); - - return taskCompletionSource.Task; - } - - return TryEnqueueAsync(dispatcher, function, priority); - } - - /// - /// Invokes a given function on the target and returns a - /// that acts as a proxy for the one returned by the given function. - /// - /// The return type of to relay through the returned . - /// The target to invoke the code on. - /// The to invoke. - /// The priority level for the function to invoke. - /// A that relays the one returned by . - /// If the current thread has access to , will be invoked directly. - public static Task EnqueueAsync(this Dispatcher dispatcher, Func> function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (dispatcher.CheckAccess()) - { - try - { - if (function() is Task awaitableResult) - { - return awaitableResult; - } -#if !NET452 - return Task.FromException(new InvalidOperationException("The Task returned by function cannot be null.")); -#else - return new Task(() => throw new InvalidOperationException("The Task returned by function cannot be null.")); -#endif - } - catch (Exception e) - { -#if !NET452 - return Task.FromException(e); -#else - return new Task(() => throw e); -#endif - } - } - - static Task TryEnqueueAsync(Dispatcher dispatcher, Func> function, DispatcherPriority priority) - { - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher.InvokeAsync(async () => - { - try - { - if (function() is Task awaitableResult) - { - var result = await awaitableResult.ConfigureAwait(false); - - taskCompletionSource.SetResult(result); - } - else - { - taskCompletionSource.SetException(GetEnqueueException("The Task returned by function cannot be null.")); - } - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }, priority); - - return taskCompletionSource.Task; - } - - return TryEnqueueAsync(dispatcher, function, priority); - } - - /// - /// Creates an to return when an enqueue operation fails. - /// - /// The message of the exception. - /// An with a specified message. - [MethodImpl(MethodImplOptions.NoInlining)] - private static InvalidOperationException GetEnqueueException(string message) - { - return new InvalidOperationException(message); - } - } -} \ No newline at end of file diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/DispatcherHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/DispatcherHelper.cs deleted file mode 100644 index 8347717..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/DispatcherHelper.cs +++ /dev/null @@ -1,419 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Threading; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - /// - /// This class provides static methods helper for executing code in UI thread of the main window. - /// - public static class DispatcherHelper - { - public static void DoEvents(DispatcherPriority priority = DispatcherPriority.Background) - { - DispatcherFrame frame = new DispatcherFrame(); - Dispatcher.CurrentDispatcher.BeginInvoke( - priority, - new DispatcherOperationCallback(ExitFrame), - frame); - Dispatcher.PushFrame(frame); - } - - private static object ExitFrame(object f) - { - ((DispatcherFrame)f).Continue = false; - - return null; - } - - public static void RunOnMainThread(Action action) - { - _ = ExecuteOnUIThreadAsync(action); - } - - public static void RunOnUIThread(this DispatcherObject d, Action action) - { - _ = d.ExecuteOnUIThreadAsync(action); - } - - public static void RunOnUIThread(this Dispatcher dispatcher, Action action) - { - _ = dispatcher.AwaitableRunAsync(action); - } - - /// - /// Executes the given function on the main view's UI thread. - /// - /// Synchronous function to be executed on UI thread. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(Action function, DispatcherPriority priority = DispatcherPriority.Normal) - { - return Application.Current?.ExecuteOnUIThreadAsync(function, priority); - } - - /// - /// Executes the given function on the main view's UI thread and returns its result. - /// - /// Returned data type of the function. - /// Synchronous function to be executed on UI thread. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(Func function, DispatcherPriority priority = DispatcherPriority.Normal) - { - return Application.Current?.ExecuteOnUIThreadAsync(function, priority); - } - - /// - /// Executes the given -returning function on the main view's UI thread and returns either that - /// or a proxy that completes when the one produced by the given function completes. - /// - /// Asynchronous function to be executed asynchronously on UI thread. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - public static Task ExecuteOnUIThreadAsync(Func function, DispatcherPriority priority = DispatcherPriority.Normal) - { - return Application.Current?.ExecuteOnUIThreadAsync(function, priority); - } - - /// - /// Executes the given -returning function on the main view's UI thread and returns either that - /// or a proxy that completes when the one produced by the given function completes. - /// - /// Returned data type of the function. - /// Asynchronous function to be executed asynchronously on UI thread. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - public static Task ExecuteOnUIThreadAsync(Func> function, DispatcherPriority priority = DispatcherPriority.Normal) - { - return Application.Current?.ExecuteOnUIThreadAsync(function, priority); - } - - /// - /// Executes the given function on a given view's UI thread. - /// - /// View for the to be executed on. - /// Synchronous function to be executed on UI thread. - /// Dispatcher execution priority, default is normal - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(this DispatcherObject viewToExecuteOn, Action function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (viewToExecuteOn is null) - { - throw new ArgumentNullException(nameof(viewToExecuteOn)); - } - - return GetDispatcher(viewToExecuteOn).AwaitableRunAsync(function, priority); - } - - /// - /// Executes the given function on a given view's UI thread. - /// - /// Returned data type of the function. - /// View for the to be executed on. - /// Synchronous function with return type to be executed on UI thread. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(this DispatcherObject viewToExecuteOn, Func function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (viewToExecuteOn is null) - { - throw new ArgumentNullException(nameof(viewToExecuteOn)); - } - - return GetDispatcher(viewToExecuteOn).AwaitableRunAsync(function, priority); - } - - public static Dispatcher GetDispatcher(DispatcherObject viewToExecuteOn) - { - return viewToExecuteOn?.Dispatcher ?? Dispatcher.CurrentDispatcher; - } - - /// - /// Executes the given function on a given view's UI thread. - /// - /// View for the to be executed on. - /// Asynchronous function to be executed asynchronously on UI thread. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(this DispatcherObject viewToExecuteOn, Func function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (viewToExecuteOn is null) - { - throw new ArgumentNullException(nameof(viewToExecuteOn)); - } - - return GetDispatcher(viewToExecuteOn).AwaitableRunAsync(function, priority); - } - - /// - /// Executes the given function on a given view's UI thread. - /// - /// Returned data type of the function. - /// View for the to be executed on. - /// Asynchronous function to be executed asynchronously on UI thread. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(this DispatcherObject viewToExecuteOn, Func> function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (viewToExecuteOn is null) - { - throw new ArgumentNullException(nameof(viewToExecuteOn)); - } - - return GetDispatcher(viewToExecuteOn).AwaitableRunAsync(function, priority); - } - - /// - /// Extension method for . Offering an actual awaitable with optional result that will be executed on the given dispatcher. - /// - /// Dispatcher of a thread to run . - /// Function to be executed on the given dispatcher. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task AwaitableRunAsync(this Dispatcher dispatcher, Action function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - /* Run the function directly when we have thread access. - * Also reuse Task.CompletedTask in case of success, - * to skip an unnecessary heap allocation for every invocation. */ - if (dispatcher.CheckAccess()) - { - try - { - function(); -#if !NET452 - return Task.CompletedTask; -#else - return new Task(() => { }, default, (TaskCreationOptions)16384); -#endif - } - catch (Exception e) - { -#if !NET452 - return Task.FromException(e); -#else - return new Task(() => throw e); -#endif - } - } - - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher.InvokeAsync(() => - { - try - { - function(); - - taskCompletionSource.SetResult(null); - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }, priority); - - return taskCompletionSource.Task; - } - - /// - /// Extension method for . Offering an actual awaitable with optional result that will be executed on the given dispatcher. - /// - /// Returned data type of the function. - /// Dispatcher of a thread to run . - /// Function to be executed on the given dispatcher. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task AwaitableRunAsync(this Dispatcher dispatcher, Func function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - // Skip the dispatch, if possible - if (dispatcher.CheckAccess()) - { - try - { - return Task.FromResult(function()); - } - catch (Exception e) - { -#if !NET452 - return Task.FromException(e); -#else - return new Task(() => throw e); -#endif - } - } - - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher.InvokeAsync(() => - { - try - { - taskCompletionSource.SetResult(function()); - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }, priority); - - return taskCompletionSource.Task; - } - - /// - /// Extension method for . Offering an actual awaitable with optional result that will be executed on the given dispatcher. - /// - /// Dispatcher of a thread to run . - /// Asynchronous function to be executed on the given dispatcher. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task AwaitableRunAsync(this Dispatcher dispatcher, Func function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - /* If we have thread access, we can retrieve the task directly. - * We don't use ConfigureAwait(false) in this case, in order - * to let the caller continue its execution on the same thread - * after awaiting the task returned by this function. */ - if (dispatcher.CheckAccess()) - { - try - { - if (function() is Task awaitableResult) - { - return awaitableResult; - } -#if !NET452 - return Task.FromException(new InvalidOperationException("The Task returned by function cannot be null.")); -#else - return new Task(() => throw new InvalidOperationException("The Task returned by function cannot be null.")); -#endif - } - catch (Exception e) - { -#if !NET452 - return Task.FromException(e); -#else - return new Task(() => throw e); -#endif - } - } - - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher.InvokeAsync(async () => - { - try - { - if (function() is Task awaitableResult) - { - await awaitableResult.ConfigureAwait(false); - - taskCompletionSource.SetResult(null); - } - else - { - taskCompletionSource.SetException(new InvalidOperationException("The Task returned by function cannot be null.")); - } - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }, priority); - - return taskCompletionSource.Task; - } - - /// - /// Extension method for . Offering an actual awaitable with optional result that will be executed on the given dispatcher. - /// - /// Returned data type of the function. - /// Dispatcher of a thread to run . - /// Asynchronous function to be executed asynchronously on the given dispatcher. - /// Dispatcher execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task AwaitableRunAsync(this Dispatcher dispatcher, Func> function, DispatcherPriority priority = DispatcherPriority.Normal) - { - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - // Skip the dispatch, if possible - if (dispatcher.CheckAccess()) - { - try - { - if (function() is Task awaitableResult) - { - return awaitableResult; - } -#if !NET452 - return Task.FromException(new InvalidOperationException("The Task returned by function cannot be null.")); -#else - return new Task(() => throw new InvalidOperationException("The Task returned by function cannot be null.")); -#endif - } - catch (Exception e) - { -#if !NET452 - return Task.FromException(e); -#else - return new Task(() => throw e); -#endif - } - } - - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher.InvokeAsync(async () => - { - try - { - if (function() is Task awaitableResult) - { - var result = await awaitableResult.ConfigureAwait(false); - - taskCompletionSource.SetResult(result); - } - else - { - taskCompletionSource.SetException(new InvalidOperationException("The Task returned by function cannot be null.")); - } - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }, priority); - - return taskCompletionSource.Task; - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/DoubleUtil.cs b/source/iNKORE.UI.WPF.Modern/Helpers/DoubleUtil.cs deleted file mode 100644 index cbc6d93..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/DoubleUtil.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class DoubleUtil - { - public static int DoubleToInt(double val) - { - return 0 < val ? (int)(val + 0.5) : (int)(val - 0.5); - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/DpiHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/DpiHelper.cs deleted file mode 100644 index 1240981..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/DpiHelper.cs +++ /dev/null @@ -1,83 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - using System; - using System.Diagnostics.CodeAnalysis; - using System.Windows; - using System.Windows.Media; - - internal static class DpiHelper - { - [ThreadStatic] - private static Matrix _transformToDevice; - [ThreadStatic] - private static Matrix _transformToDip; - - /// - /// Convert a point in device independent pixels (1/96") to a point in the system coordinates. - /// - /// A point in the logical coordinate system. - /// Returns the parameter converted to the system's coordinates. - public static Point LogicalPixelsToDevice(Point logicalPoint, double dpiScaleX, double dpiScaleY) - { - _transformToDevice = Matrix.Identity; - _transformToDevice.Scale(dpiScaleX, dpiScaleY); - return _transformToDevice.Transform(logicalPoint); - } - - /// - /// Convert a point in system coordinates to a point in device independent pixels (1/96"). - /// - /// A point in the physical coordinate system. - /// Returns the parameter converted to the device independent coordinate system. - public static Point DevicePixelsToLogical(Point devicePoint, double dpiScaleX, double dpiScaleY) - { - _transformToDip = Matrix.Identity; - _transformToDip.Scale(1d / dpiScaleX, 1d / dpiScaleY); - return _transformToDip.Transform(devicePoint); - } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - public static Rect LogicalRectToDevice(Rect logicalRectangle, double dpiScaleX, double dpiScaleY) - { - Point topLeft = LogicalPixelsToDevice(new Point(logicalRectangle.Left, logicalRectangle.Top), dpiScaleX, dpiScaleY); - Point bottomRight = LogicalPixelsToDevice(new Point(logicalRectangle.Right, logicalRectangle.Bottom), dpiScaleX, dpiScaleY); - - return new Rect(topLeft, bottomRight); - } - - public static Rect DeviceRectToLogical(Rect deviceRectangle, double dpiScaleX, double dpiScaleY) - { - Point topLeft = DevicePixelsToLogical(new Point(deviceRectangle.Left, deviceRectangle.Top), dpiScaleX, dpiScaleY); - Point bottomRight = DevicePixelsToLogical(new Point(deviceRectangle.Right, deviceRectangle.Bottom), dpiScaleX, dpiScaleY); - - return new Rect(topLeft, bottomRight); - } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - public static Size LogicalSizeToDevice(Size logicalSize, double dpiScaleX, double dpiScaleY) - { - Point pt = LogicalPixelsToDevice(new Point(logicalSize.Width, logicalSize.Height), dpiScaleX, dpiScaleY); - - return new Size { Width = pt.X, Height = pt.Y }; - } - - public static Size DeviceSizeToLogical(Size deviceSize, double dpiScaleX, double dpiScaleY) - { - Point pt = DevicePixelsToLogical(new Point(deviceSize.Width, deviceSize.Height), dpiScaleX, dpiScaleY); - - return new Size(pt.X, pt.Y); - } - - public static Thickness LogicalThicknessToDevice(Thickness logicalThickness, double dpiScaleX, double dpiScaleY) - { - Point topLeft = LogicalPixelsToDevice(new Point(logicalThickness.Left, logicalThickness.Top), dpiScaleX, dpiScaleY); - Point bottomRight = LogicalPixelsToDevice(new Point(logicalThickness.Right, logicalThickness.Bottom), dpiScaleX, dpiScaleY); - - return new Thickness(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y); - } - } -} \ No newline at end of file diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/Extensions.cs b/source/iNKORE.UI.WPF.Modern/Helpers/Extensions.cs deleted file mode 100644 index 98a6589..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/Extensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Windows.Media; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class Extensions - { - public static GeneralTransform SafeTransformToVisual(this Visual self, Visual visual) - { - if (self.FindCommonVisualAncestor(visual) != null) - { - return self.TransformToVisual(visual); - } - return Transform.Identity; - } - - public static object GetProperty(this object item, string name) => item.GetType()?.GetProperty(name)?.GetValue(item, null); - - public static void SetProperty(this object item, string name, object value) => item.GetType()?.GetProperty(name)?.SetValue(item, value); - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/FontHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/FontHelper.cs deleted file mode 100644 index bf16ed6..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/FontHelper.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class FontHelper - { - public static string SymbolThemeFontFamilyKey => GetSymbolThemeFontFamily(); - - private static string GetSymbolThemeFontFamily() - { - if (CheckSysFontExisting("Segoe Fluent Icons")) - { - return "SegoeFluentIcons"; - } - else if (CheckSysFontExisting("Segoe MDL2 Assets")) - { - return "SegoeMDL2Assets"; - } - else if (CheckSysFontExisting("Segoe UI Symbol")) - { - return "SegoeUISymbol"; - } - else - { - return "FluentSystemIcons"; - } - } - - public static bool CheckSysFontExisting(string fontName = "文鼎細黑") - { - FontFamily font; - try - { - font = new FontFamily(fontName); - if (!font.FamilyNames.Any()) - { - return false; - } - } - catch (Exception) - { - return false; - } - return true; - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/GridLengthHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/GridLengthHelper.cs deleted file mode 100644 index 786b5da..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/GridLengthHelper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Windows; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class GridLengthHelper - { - public static GridLength FromPixels(double pixels) - { - return new GridLength(pixels); - } - - public static GridLength FromValueAndType(double value, GridUnitType type) - { - return new GridLength(value, type); - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/MenuDropAlignmentHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/MenuDropAlignmentHelper.cs deleted file mode 100644 index 524de02..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/MenuDropAlignmentHelper.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.Reflection; -using System.Windows; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class MenuDropAlignmentHelper - { - private static readonly FieldInfo _menuDropAlignmentField; - - static MenuDropAlignmentHelper() - { - try - { - _menuDropAlignmentField = typeof(SystemParameters).GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static); - } - catch (Exception) - { - } - - Debug.Assert(_menuDropAlignmentField != null); - if (_menuDropAlignmentField != null) - { - EnsureStandardPopupAlignment(); - SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged; - } - } - - public static void EnsureStandardPopupAlignment() - { - if (SystemParameters.MenuDropAlignment) - { - try - { - _menuDropAlignmentField.SetValue(null, false); - } - catch (Exception) - { - } - - Debug.Assert(!SystemParameters.MenuDropAlignment); - } - } - - private static void SystemParameters_StaticPropertyChanged(object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == nameof(SystemParameters.MenuDropAlignment)) - { - EnsureStandardPopupAlignment(); - } - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/MergedDictionariesHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/MergedDictionariesHelper.cs deleted file mode 100644 index 46edc91..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/MergedDictionariesHelper.cs +++ /dev/null @@ -1,127 +0,0 @@ -using System; -using System.Collections.ObjectModel; -using System.Windows; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class MergedDictionariesHelper - { - //public static void Add(this Collection mergedDictionaries, Uri source, bool useCache = true) - //{ - // var dictionary = GetDictionary(source, useCache); - // if (!mergedDictionaries.Contains(dictionary)) - // { - // mergedDictionaries.Add(dictionary); - // } - //} - - //public static void AddFirst(this Collection mergedDictionaries, Uri source, bool useCache = true) - //{ - // mergedDictionaries.Insert(0, source, useCache); - //} - - //public static void Insert(this Collection mergedDictionaries, int index, Uri source, bool useCache = true) - //{ - // var dictionary = GetDictionary(source, useCache); - // if (!mergedDictionaries.Contains(dictionary)) - // { - // mergedDictionaries.Insert(index, dictionary); - // } - //} - - //public static void Remove(this Collection mergedDictionaries, Uri source) - //{ - // bool removed = false; - - // if (ResourceDictionaryCache.TryGetDictionary(source, out ResourceDictionary dictionary)) - // { - // removed = mergedDictionaries.Remove(dictionary); - // } - - // if (!removed) - // { - // for (int i = mergedDictionaries.Count - 1; i >= 0; i--) - // { - // dictionary = mergedDictionaries[i]; - // if (dictionary != null && dictionary.Source == source) - // { - // mergedDictionaries.RemoveAt(i); - // } - // } - // } - //} - - public static void AddIfNotNull(this Collection mergedDictionaries, ResourceDictionary item) - { - if (item != null) - { - mergedDictionaries.Add(item); - } - } - - public static void RemoveIfNotNull(this Collection mergedDictionaries, ResourceDictionary item) - { - if (item != null) - { - mergedDictionaries.Remove(item); - } - } - - public static void InsertOrReplace(this Collection mergedDictionaries, int index, ResourceDictionary item) - { - if (mergedDictionaries.Count > index) - { - mergedDictionaries[index] = item; - } - else - { - mergedDictionaries.Insert(index, item); - } - } - - public static void RemoveAll(this Collection mergedDictionaries) where T : ResourceDictionary - { - for (int i = mergedDictionaries.Count - 1; i >= 0; i--) - { - if (mergedDictionaries[i] is T) - { - mergedDictionaries.RemoveAt(i); - } - } - } - - public static void InsertIfNotExists(this Collection mergedDictionaries, int index, ResourceDictionary item) - { - if (!mergedDictionaries.Contains(item)) - { - mergedDictionaries.Insert(index, item); - } - } - - public static void Swap(this Collection mergedDictionaries, int index1, int index2) - { - if (index1 == index2) - { - return; - } - - var smallIndex = Math.Min(index1, index2); - var largeIndex = Math.Max(index1, index2); - var tmp = mergedDictionaries[smallIndex]; - mergedDictionaries.RemoveAt(smallIndex); - mergedDictionaries.Insert(largeIndex, tmp); - } - - //private static ResourceDictionary GetDictionary(Uri source, bool useCache) - //{ - // if (useCache) - // { - // return ResourceDictionaryCache.GetOrCreateDictionary(source); - // } - // else - // { - // return new ResourceDictionary { Source = source }; - // } - //} - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/OSVersionHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/OSVersionHelper.cs deleted file mode 100644 index 70fc699..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/OSVersionHelper.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - public static class OSVersionHelper - { - public static readonly Version OSVersion = GetOSVersion(); - - public static bool IsWindowsNT { get; } = Environment.OSVersion.Platform == PlatformID.Win32NT; - - public static bool IsWindowsVistaOrGreater { get; } = IsWindowsNT && OSVersion >= new Version(6, 0); - - public static bool IsWindows7OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(6, 1); - - public static bool IsWindows8OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(6, 2); - - public static bool IsWindows81OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(6, 2); - - public static bool IsWindows10OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(10, 0); - - public static bool IsWindows11OrGreater { get; } = IsWindowsNT && OSVersion >= new Version(10, 0, 21996); - - private static Version GetOSVersion() - { - var osv = new RTL_OSVERSIONINFOEX(); - osv.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osv); - int ret = RtlGetVersion(out osv); - Debug.Assert(ret == 0); - return new Version((int)osv.dwMajorVersion, (int)osv.dwMinorVersion, (int)osv.dwBuildNumber); - } - - [DllImport("ntdll.dll")] - private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation); - - [StructLayout(LayoutKind.Sequential)] - private struct RTL_OSVERSIONINFOEX - { - internal uint dwOSVersionInfoSize; - internal uint dwMajorVersion; - internal uint dwMinorVersion; - internal uint dwBuildNumber; - internal uint dwPlatformId; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] - internal string szCSDVersion; - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/PackagedAppHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/PackagedAppHelper.cs deleted file mode 100644 index c1886d9..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/PackagedAppHelper.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Runtime.InteropServices; -using System.Text; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - public static class PackagedAppHelper - { - private const long APPMODEL_ERROR_NO_PACKAGE = 15700L; - - public static bool IsPackagedApp - { - get - { - if (OSVersionHelper.IsWindows8OrGreater) - { - int length = 0; - var sb = new StringBuilder(0); - GetCurrentPackageFullName(ref length, sb); - - sb.Length = length; - int result = GetCurrentPackageFullName(ref length, sb); - - return result != APPMODEL_ERROR_NO_PACKAGE; - } - - return false; - } - } - - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - private static extern int GetCurrentPackageFullName(ref int packageFullNameLength, StringBuilder packageFullName); - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/Styles/AcrylicHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/Styles/AcrylicHelper.cs index 088fc0f..2ecf3fd 100644 --- a/source/iNKORE.UI.WPF.Modern/Helpers/Styles/AcrylicHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Helpers/Styles/AcrylicHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System; using System.Collections.Generic; using System.Linq; diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/Styles/MicaHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/Styles/MicaHelper.cs index c13ecbe..da3249d 100644 --- a/source/iNKORE.UI.WPF.Modern/Helpers/Styles/MicaHelper.cs +++ b/source/iNKORE.UI.WPF.Modern/Helpers/Styles/MicaHelper.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using iNKORE.UI.WPF.Modern.Native; using System; using System.Collections.Generic; diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs b/source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs index 980285a..a287f54 100644 --- a/source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs +++ b/source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Common; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Controls.Primitives; using iNKORE.UI.WPF.Modern.Helpers; using iNKORE.UI.WPF.Modern.Native; diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/ThicknessHelper.cs b/source/iNKORE.UI.WPF.Modern/Helpers/ThicknessHelper.cs deleted file mode 100644 index c1ccc01..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/ThicknessHelper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Windows; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - internal static class ThicknessHelper - { - public static Thickness FromLengths(double left, double top, double right, double bottom) - { - return new Thickness(left, top, right, bottom); - } - - public static Thickness FromUniformLength(double uniformLength) - { - return new Thickness(uniformLength); - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/Helpers/VisualTree.cs b/source/iNKORE.UI.WPF.Modern/Helpers/VisualTree.cs deleted file mode 100644 index 3255348..0000000 --- a/source/iNKORE.UI.WPF.Modern/Helpers/VisualTree.cs +++ /dev/null @@ -1,230 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Windows; -using System.Windows.Media; - -namespace iNKORE.UI.WPF.Modern.Helpers -{ - /// - /// Defines a collection of extensions methods for UI. - /// - public static class VisualTree - { - /// - /// Find descendant control using its name. - /// - /// Parent element. - /// Name of the control to find - /// Descendant control or null if not found. - public static FrameworkElement FindDescendantByName(this DependencyObject element, string name) - { - if (element == null || string.IsNullOrWhiteSpace(name)) - { - return null; - } - - if (name.Equals((element as FrameworkElement)?.Name, StringComparison.OrdinalIgnoreCase)) - { - return element as FrameworkElement; - } - - var childCount = VisualTreeHelper.GetChildrenCount(element); - for (int i = 0; i < childCount; i++) - { - var result = VisualTreeHelper.GetChild(element, i).FindDescendantByName(name); - if (result != null) - { - return result; - } - } - - return null; - } - - /// - /// Find first descendant control of a specified type. - /// - /// Type to search for. - /// Parent element. - /// Descendant control or null if not found. - public static T FindDescendant(this DependencyObject element) - where T : DependencyObject - { - T retValue = null; - var childrenCount = VisualTreeHelper.GetChildrenCount(element); - - for (var i = 0; i < childrenCount; i++) - { - var child = VisualTreeHelper.GetChild(element, i); - var type = child as T; - if (type != null) - { - retValue = type; - break; - } - - retValue = child.FindDescendant(); - - if (retValue != null) - { - break; - } - } - - return retValue; - } - - /// - /// Find first descendant control of a specified type. - /// - /// Parent element. - /// Type of descendant. - /// Descendant control or null if not found. - public static object FindDescendant(this DependencyObject element, Type type) - { - object retValue = null; - var childrenCount = VisualTreeHelper.GetChildrenCount(element); - - for (var i = 0; i < childrenCount; i++) - { - var child = VisualTreeHelper.GetChild(element, i); - if (child.GetType() == type) - { - retValue = child; - break; - } - - retValue = child.FindDescendant(type); - - if (retValue != null) - { - break; - } - } - - return retValue; - } - - /// - /// Find all descendant controls of the specified type. - /// - /// Type to search for. - /// Parent element. - /// Descendant controls or empty if not found. - public static IEnumerable FindDescendants(this DependencyObject element) - where T : DependencyObject - { - var childrenCount = VisualTreeHelper.GetChildrenCount(element); - - for (var i = 0; i < childrenCount; i++) - { - var child = VisualTreeHelper.GetChild(element, i); - var type = child as T; - if (type != null) - { - yield return type; - } - - foreach (T childofChild in child.FindDescendants()) - { - yield return childofChild; - } - } - } - - /// - /// Find visual ascendant control using its name. - /// - /// Parent element. - /// Name of the control to find - /// Descendant control or null if not found. - public static FrameworkElement FindAscendantByName(this DependencyObject element, string name) - { - if (element == null || string.IsNullOrWhiteSpace(name)) - { - return null; - } - - var parent = VisualTreeHelper.GetParent(element); - - if (parent == null) - { - return null; - } - - if (name.Equals((parent as FrameworkElement)?.Name, StringComparison.OrdinalIgnoreCase)) - { - return parent as FrameworkElement; - } - - return parent.FindAscendantByName(name); - } - - /// - /// Find first visual ascendant control of a specified type. - /// - /// Type to search for. - /// Child element. - /// Ascendant control or null if not found. - public static T FindAscendant(this DependencyObject element) - where T : DependencyObject - { - var parent = VisualTreeHelper.GetParent(element); - - if (parent == null) - { - return null; - } - - if (parent is T) - { - return parent as T; - } - - return parent.FindAscendant(); - } - - /// - /// Find first visual ascendant control of a specified type. - /// - /// Child element. - /// Type of ascendant to look for. - /// Ascendant control or null if not found. - public static object FindAscendant(this DependencyObject element, Type type) - { - var parent = VisualTreeHelper.GetParent(element); - - if (parent == null) - { - return null; - } - - if (parent.GetType() == type) - { - return parent; - } - - return parent.FindAscendant(type); - } - - /// - /// Find all visual ascendants for the element. - /// - /// Child element. - /// A collection of parent elements or null if none found. - public static IEnumerable FindAscendants(this DependencyObject element) - { - var parent = VisualTreeHelper.GetParent(element); - - while (parent != null) - { - yield return parent; - parent = VisualTreeHelper.GetParent(parent); - } - } - } -} diff --git a/source/iNKORE.UI.WPF.Modern/ThemeManager.cs b/source/iNKORE.UI.WPF.Modern/ThemeManager.cs index e7d5724..b9d5771 100644 --- a/source/iNKORE.UI.WPF.Modern/ThemeManager.cs +++ b/source/iNKORE.UI.WPF.Modern/ThemeManager.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Common; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Common; using iNKORE.UI.WPF.Modern.Helpers; using iNKORE.UI.WPF.Modern.Themes.DesignTime; using System; diff --git a/source/iNKORE.UI.WPF.Modern/ThemeResources.cs b/source/iNKORE.UI.WPF.Modern/ThemeResources.cs index 9e6e886..f45b7b3 100644 --- a/source/iNKORE.UI.WPF.Modern/ThemeResources.cs +++ b/source/iNKORE.UI.WPF.Modern/ThemeResources.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System; using System.ComponentModel; using System.Diagnostics; diff --git a/source/iNKORE.UI.WPF.Modern/Themes/DesignTime/IntellisenseResourcesBase.cs b/source/iNKORE.UI.WPF.Modern/Themes/DesignTime/IntellisenseResourcesBase.cs index be65b89..ee54851 100644 --- a/source/iNKORE.UI.WPF.Modern/Themes/DesignTime/IntellisenseResourcesBase.cs +++ b/source/iNKORE.UI.WPF.Modern/Themes/DesignTime/IntellisenseResourcesBase.cs @@ -1,4 +1,5 @@ -using iNKORE.UI.WPF.Modern.Helpers; +using iNKORE.UI.WPF.Helpers; +using iNKORE.UI.WPF.Modern.Helpers; using System; using System.ComponentModel; using System.Windows; diff --git a/source/iNKORE.UI.WPF.Modern/UISettingsResources.cs b/source/iNKORE.UI.WPF.Modern/UISettingsResources.cs index 6b7e897..67827cd 100644 --- a/source/iNKORE.UI.WPF.Modern/UISettingsResources.cs +++ b/source/iNKORE.UI.WPF.Modern/UISettingsResources.cs @@ -1,6 +1,7 @@ using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Threading; +using iNKORE.UI.WPF.Helpers; using iNKORE.UI.WPF.Modern.Helpers; using Microsoft.Win32; using Windows.Foundation.Metadata; diff --git a/source/iNKORE.UI.WPF.Modern/iNKORE.UI.WPF.Modern.csproj b/source/iNKORE.UI.WPF.Modern/iNKORE.UI.WPF.Modern.csproj index 822d69f..8c57597 100644 --- a/source/iNKORE.UI.WPF.Modern/iNKORE.UI.WPF.Modern.csproj +++ b/source/iNKORE.UI.WPF.Modern/iNKORE.UI.WPF.Modern.csproj @@ -1,7 +1,7 @@  - net6.0-windows10.0.18362.0;net452 + net6.0-windows10.0.18362.0;net462 true true en-US @@ -76,6 +76,10 @@ + + + +